Skip to content

Commit ef02cfe

Browse files
committed
docs(near): add near guides
1 parent c0b383e commit ef02cfe

File tree

5 files changed

+63
-42
lines changed

5 files changed

+63
-42
lines changed

target_chains/near/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Pyth NEAR
2+
3+
This directory contains the Pyth contract for NEAR, examples, and utilities to deploy. Within the `example/`
4+
directory you will find an example skeleton NEAR contract that updates and uses a price. You can find
5+
updates to test with from the Hermes API. Additionally see the `scripts/update.sh` script for an example
6+
of how to manually submit a price update from the CLI.
7+
8+
## Deployment
9+
10+
Deploying the NEAR contract has three steps:
11+
12+
1. Create a NEAR key with `near generate-key`
13+
2. Fetch NEAR tokens from an available faucet, at last deploy around 100~ NEAR were needed.
14+
3. See the example deploy script in `scripts/deploy.sh` to deploy the contract. You can find a codehash by:
15+
- `sha256sum pyth.wasm` after building the contract.
16+
- `list(bytes.fromhex(hash))` in Python to get a byte array.
17+
- Replace the `codehash` field in deploy.sh for the initial codehash.
18+
19+
## Further Documentation
20+
21+
You can find more in-depth documentation on the [Pyth Website][pyth website] for a more in-depth guide to
22+
working with Pyth concepts in general in the context of NEAR.
23+
24+
[pyth website]: https://docs.pyth.network/documentation/pythnet-price-feeds/near

target_chains/near/receiver/deploy.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.

target_chains/near/receiver/transfers.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

target_chains/near/scripts/deploy.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
# This is an example payload for deploying the NEAR receiver contract. Note that the codehash can be obtained
4+
# by `sha256sum` on the compiled contract. The initial and governance sources are the PythNet emitters for
5+
# governance payloads.
6+
INIT_ARGS=$(
7+
cat <<-EOF
8+
{
9+
"wormhole": "wormhole.wormhole.testnet",
10+
"codehash": [113, 49, 20, 252, 226, 220, 48, 15, 139, 92, 255, 117, 94, 178, 130, 162, 252, 5, 252, 188, 87, 122, 50, 175, 109, 12, 26, 189, 9, 107, 214, 116],
11+
"initial_source": {
12+
"emitter": [225, 1, 250, 237, 172, 88, 81, 227, 43, 155, 35, 181, 249, 65, 26, 140, 43, 172, 74, 174, 62, 212, 221, 123, 129, 29, 209, 167, 46, 164, 170, 113],
13+
"chain": 26
14+
},
15+
"gov_source": {
16+
"emitter": [86, 53, 151, 154, 34, 28, 52, 147, 30, 50, 98, 11, 146, 147, 164, 99, 6, 85, 85, 234, 113, 254, 151, 205, 98, 55, 173, 232, 117, 177, 46, 158],
17+
"chain": 1
18+
},
19+
"update_fee": "1",
20+
"stale_threshold": 60
21+
}
22+
EOF
23+
)
24+
25+
# Feed through jq to get compressed JSON to avoid CLI weirdness.
26+
INIT_JSON=$(echo "$INIT_ARGS" | jq -c '.' -M)
27+
28+
# Deploy..
29+
near deploy \
30+
--accountId "pyth.testnet" \
31+
--wasmFile pyth.wasm \
32+
--initFunction new \
33+
--initArgs "$INIT_JSON"
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22

3+
# This is an example payload for subitting a price update from Hermes to a NEAR contract.
34
UPDATE_ARGS=$(
45
cat <<-EOF
56
{
@@ -8,12 +9,14 @@ UPDATE_ARGS=$(
89
EOF
910
)
1011

12+
# Feed through jq to get compressed JSON to avoid CLI weirdness.
1113
UPDATE_JSON=$(echo "$UPDATE_ARGS" | jq -c '.' -M)
1214

15+
# Submit.
1316
near call \
14-
--accountId "780e82bd52465f8a4f5ed8cf5a30666eb41208849956bf87a377da9d8174e2b7" \
17+
--accountId "780e82bd52465f8a4f5ed8cf5a30666eb41208849956bf87a377da9d8174e2b7" \
1518
780e82bd52465f8a4f5ed8cf5a30666eb41208849956bf87a377da9d8174e2b7 \
16-
update_price_feed \
19+
update_price_feed \
1720
--gas 300000000000000 \
1821
--deposit 1 \
19-
--args "$UPDATE_JSON"
22+
--args "$UPDATE_JSON"

0 commit comments

Comments
 (0)