Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

Commit 2e0ed09

Browse files
authored
Improve repo and pyth-evm-js docs (#78)
* Add *mnemonic* to gitignore to avoid mistakes * Update EvmRelay.ts to make it simpler
1 parent 859204f commit 2e0ed09

File tree

3 files changed

+20
-48
lines changed

3 files changed

+20
-48
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
lib
33
.dccache
4+
*mnemonic*

pyth-evm-js/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,14 @@ npm run example-client -- --endpoint https://xc-testnet.pyth.network --price-ids
142142
You can run this example with `npm run example-relay`. A full command that updates BTC and ETH prices on the BNB Chain testnet network looks like so:
143143

144144
```bash
145-
npm run example-relay -- --network bnb_testnet --mnemonic "my good mnemonic" --endpoint https://xc-testnet.pyth.network --price-ids 0xf9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b 0xca80ba6dc32e08d06f1aa886011eed1d77c77be9eb761cc10d72b7d0a2fd57a6
145+
npm run example-relay -- \
146+
--network "https://data-seed-prebsc-1-s1.binance.org:8545" \
147+
--pyth-contract "0xd7308b14BF4008e7C7196eC35610B1427C5702EA"\
148+
--mnemonic "my good mnemonic" \
149+
--endpoint https://xc-testnet.pyth.network \
150+
--price-ids \
151+
"0xf9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b" \
152+
"0xca80ba6dc32e08d06f1aa886011eed1d77c77be9eb761cc10d72b7d0a2fd57a6"
146153
```
147154

148155
## Price Service endpoints

pyth-evm-js/src/examples/EvmRelay.ts

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ import Web3 from "web3";
22
import yargs from "yargs";
33
import { hideBin } from "yargs/helpers";
44

5-
import { EvmPriceServiceConnection, CONTRACT_ADDR } from "../index";
5+
import { EvmPriceServiceConnection } from "../index";
66
import HDWalletProvider from "@truffle/hdwallet-provider";
77
import PythInterfaceAbi from "@pythnetwork/pyth-sdk-solidity/abis/IPyth.json";
88

99
const argv = yargs(hideBin(process.argv))
1010
.option("network", {
11-
description:
12-
"Network to relay on. Provide node url if you are using anything other than " +
13-
"[bnb_testnet, fuji, fantom_testnet, ropsten, goerli, mumbai]",
11+
description: "RPC of the network to relay on.",
12+
type: "string",
1413
required: true,
15-
default: "bsc_testnet",
1614
})
1715
.option("endpoint", {
1816
description:
@@ -21,10 +19,9 @@ const argv = yargs(hideBin(process.argv))
2119
required: true,
2220
})
2321
.option("pyth-contract", {
24-
description:
25-
"Pyth contract address. You should provide this value if you are using a local network",
22+
description: "Pyth contract address.",
2623
type: "string",
27-
required: false,
24+
required: true,
2825
})
2926
.option("price-ids", {
3027
description:
@@ -45,45 +42,8 @@ const argv = yargs(hideBin(process.argv))
4542
})
4643
.parseSync();
4744

48-
const CONFIG: Record<string, any> = {
49-
bnb_testnet: {
50-
network: "https://data-seed-prebsc-1-s1.binance.org:8545",
51-
},
52-
fuji: {
53-
network: "https://api.avax-test.network/ext/bc/C/rpc",
54-
},
55-
fantom_testnet: {
56-
network: "https://rpc.testnet.fantom.network/",
57-
},
58-
ropsten: {
59-
network: "https://ropsten.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161",
60-
},
61-
goerli: {
62-
network: "https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161",
63-
},
64-
mumbai: {
65-
network: "https://matic-mumbai.chainstacklabs.com",
66-
},
67-
aurora_testnet: {
68-
network: "https://testnet.aurora.dev",
69-
},
70-
};
71-
72-
let network: string;
73-
let pythContractAddr: string;
74-
75-
if (CONFIG[argv.network] !== undefined) {
76-
network = CONFIG[argv.network].network;
77-
pythContractAddr = CONTRACT_ADDR[argv.network];
78-
} else {
79-
network = argv.network;
80-
if (argv.pythContract === undefined) {
81-
throw new Error(
82-
"You should provide pyth contract address when using a custom network"
83-
);
84-
}
85-
pythContractAddr = argv.pythContract;
86-
}
45+
const network = argv.network;
46+
const pythContractAddr = argv.pythContract;
8747

8848
const connection = new EvmPriceServiceConnection(argv.endpoint);
8949

@@ -124,6 +84,10 @@ async function run() {
12484
.send({ value: updateFee })
12585
.on("transactionHash", (hash: string) => {
12686
console.log(`Tx hash: ${hash}`);
87+
})
88+
.on("error", (err: any, receipt: any) => {
89+
console.error(receipt);
90+
throw err;
12791
});
12892

12993
provider.engine.stop();

0 commit comments

Comments
 (0)