Skip to content

Commit db371c9

Browse files
committed
fix: run precommit
1 parent 71404fb commit db371c9

File tree

1 file changed

+53
-41
lines changed
  • pages/price-feeds/use-real-time-data

1 file changed

+53
-41
lines changed

pages/price-feeds/use-real-time-data/near.mdx

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ are as follows:
1111

1212
1. [`update_price_feeds`](#update_price_feeds)
1313
_(updates Pyth smart contract with the price feed you provide)_
14+
1415
- args: `data`
1516
- type: `object`
1617
- example: `{ "data": "504e41...' }`
@@ -22,7 +23,7 @@ are as follows:
2223

2324
These functions are core for interacting with Pyth price feeds in
2425
NEAR-based applications, providing a reliable and up-to-date source of
25-
price information.
26+
price information.
2627

2728
For a full overview of methods provided by the NEAR
2829
contract, see [the interface](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/near/receiver/src/ext.rs)] exposed by the receiver contract.
@@ -68,33 +69,39 @@ Here is a node.js example of fetching the latest price feed using `/v2/updates/p
6869
`Example:`
6970

7071
```js
71-
const axios = require('axios');
72+
const axios = require("axios");
7273

7374
// There are separate endpoints for testnet and mainnet
74-
const HERMES_TESTNET_URL = 'https://hermes-beta.pyth.network';
75-
const HERMES_MAINNET_URL = 'https://hermes.pyth.network';
75+
const HERMES_TESTNET_URL = "https://hermes-beta.pyth.network";
76+
const HERMES_MAINNET_URL = "https://hermes.pyth.network";
7677

7778
async function getHermesPriceData(priceId, network) {
7879
try {
7980
let url;
80-
network === 'testnet'
81+
network === "testnet"
8182
? (url = HERMES_TESTNET_URL)
8283
: (url = HERMES_MAINNET_URL);
8384

8485
// Fetch the price data from the Hermes API
85-
const response = await axios.get(`${url}/v2/updates/price/latest?ids[]=${priceId}`);
86+
const response = await axios.get(
87+
`${url}/v2/updates/price/latest?ids[]=${priceId}`
88+
);
8689

8790
return response.data.binary.data[0];
8891
} catch (error) {
89-
console.error('Error:', error.response ? error.response.data : error.message);
92+
console.error(
93+
"Error:",
94+
error.response ? error.response.data : error.message
95+
);
9096
}
9197
}
9298

9399
module.exports = { getHermesPriceData };
94100
```
95101

96-
<center>z
97-
[See full example on GitHub](https://github.com/near-examples/near-js/blob/main/node-js/utils/fetch-hermes-price-data.js)
102+
<center>
103+
z [See full example on
104+
GitHub](https://github.com/near-examples/near-js/blob/main/node-js/utils/fetch-hermes-price-data.js)
98105
</center>
99106

100107
---
@@ -122,7 +129,7 @@ npm install -g near-cli-rs@latest
122129

123130
```
124131

125-
This CLI allows you to simply run `near` and let the prompts guide you through the process.
132+
This CLI allows you to simply run `near` and let the prompts guide you through the process.
126133

127134
To quickly create a NEAR account, run the following command (replacing `your-new-account.testnet` with your desired account name):
128135

@@ -135,10 +142,11 @@ network-config testnet \
135142
create
136143
```
137144

138-
To perform a contract call to the Pyth Oracle contract, run the following command:
145+
To perform a contract call to the Pyth Oracle contract, run the following command:
146+
147+
Replace:
139148

140-
Replace:
141-
- `your-account.testnet` with your account name
149+
- `your-account.testnet` with your account name
142150
- `'{"data": "504e41550100..."}'` with your off-chain price feed
143151

144152
```
@@ -166,43 +174,46 @@ To setup a NEAR connection, we'll create a `connect.js` file that will initializ
166174

167175
```js
168176
// node.js imports
169-
const { join } = require('node:path');
170-
const { homedir } = require('node:os');
177+
const { join } = require("node:path");
178+
const { homedir } = require("node:os");
171179

172180
// near-js imports
173-
const { getTestnetRpcProvider, getSignerFromKeystore } = require('@near-js/client');
174-
const { UnencryptedFileSystemKeyStore } = require('@near-js/keystores-node');
181+
const {
182+
getTestnetRpcProvider,
183+
getSignerFromKeystore,
184+
} = require("@near-js/client");
185+
const { UnencryptedFileSystemKeyStore } = require("@near-js/keystores-node");
175186

176187
// initialize RPC provider and signer
177188
const nearConnect = (sender, network) => ({
178189
rpcProvider: getTestnetRpcProvider(),
179190
signer: getSignerFromKeystore(
180-
sender,
191+
sender,
181192
network,
182-
new UnencryptedFileSystemKeyStore(join(homedir(), '.near-credentials'))
183-
)
193+
new UnencryptedFileSystemKeyStore(join(homedir(), ".near-credentials"))
194+
),
184195
});
185196

186197
module.exports = { nearConnect };
187198
```
188199

189200
Next we can create a `update-oracle.js` file that will perform the contract call to update the Pyth Oracle contract's price feed.
190-
```js
191201

202+
```js
192203
// near-js imports
193204
// https://www.npmjs.com/package/@near-js/client
194-
const { nearConnect } = require('../utils/connect');
195-
const { functionCall } = require('@near-js/client');
205+
const { nearConnect } = require("../utils/connect");
206+
const { functionCall } = require("@near-js/client");
196207

197-
const sender = 'your-account.testnet';
198-
const receiver = 'pyth-oracle.testnet';
199-
const network = 'testnet';
208+
const sender = "your-account.testnet";
209+
const receiver = "pyth-oracle.testnet";
210+
const network = "testnet";
200211

201212
const PRICE_IDS = [
202213
// Price ids can be found at https://www.pyth.network/developers/price-feed-ids#near-testnet
203214
// NOTE: Ensure you are using NEAR specific price ids & remove the '0x' prefix before using them
204-
'f9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b', // BTC/USD price id
205-
'ca80ba6dc32e08d06f1aa886011eed1d77c77be9eb761cc10d72b7d0a2fd57a6', // ETH/USD price id
215+
"f9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b", // BTC/USD price id
216+
"ca80ba6dc32e08d06f1aa886011eed1d77c77be9eb761cc10d72b7d0a2fd57a6", // ETH/USD price id
206217
];
207218

208219
async function updatePythContractPriceFeeds(network) {
@@ -215,9 +226,9 @@ async function updatePythContractPriceFeeds(network) {
215226
const result = await functionCall({
216227
sender,
217228
receiver,
218-
method: 'update_price_feeds',
219-
args: { data: '504e4155010...' },
220-
deposit: 10000000000000000000000,
229+
method: "update_price_feeds",
230+
args: { data: "504e4155010..." },
231+
deposit: 10000000000000000000000,
221232
deps: { rpcProvider, signer },
222233
});
223234

@@ -228,11 +239,11 @@ async function updatePythContractPriceFeeds(network) {
228239
}
229240

230241
updatePythOracle();
231-
232242
```
233243

234244
<center>
235-
[See full example on GitHub](https://github.com/near-examples/near-js/blob/main/node-js/oracle-example/pyth-oracle-update.js)
245+
[See full example on
246+
GitHub](https://github.com/near-examples/near-js/blob/main/node-js/oracle-example/pyth-oracle-update.js)
236247
</center>
237248

238249
Although unused deposit will be refunded, you can calculate an estimate by calling the `get_update_fee_estimate` method against the Pyth contract.
@@ -274,21 +285,21 @@ Create a `get-price.js` file that will perform the view call from the Pyth Oracl
274285
```js
275286
// near-js import
276287
// https://www.npmjs.com/package/@near-js/client
277-
const { getTestnetRpcProvider, view } = require('@near-js/client');
288+
const { getTestnetRpcProvider, view } = require("@near-js/client");
278289

279290
const PRICE_IDS = [
280291
// Price ids can be found at https://www.pyth.network/developers/price-feed-ids#near-testnet
281292
// NOTE: Ensure you are using NEAR specific price ids & remove the '0x' prefix before using them
282-
'f9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b', // BTC/USD price id
283-
'ca80ba6dc32e08d06f1aa886011eed1d77c77be9eb761cc10d72b7d0a2fd57a6', // ETH/USD price id
293+
"f9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b", // BTC/USD price id
294+
"ca80ba6dc32e08d06f1aa886011eed1d77c77be9eb761cc10d72b7d0a2fd57a6", // ETH/USD price id
284295
];
285296

286297
async function getPrice(price_ID, symbol) {
287298
try {
288299
const rpcProvider = getTestnetRpcProvider();
289300
const result = await view({
290-
account: 'pyth-oracle.testnet',
291-
method: 'get_price',
301+
account: "pyth-oracle.testnet",
302+
method: "get_price",
292303
args: { price_identifier: price_ID },
293304
deps: { rpcProvider },
294305
});
@@ -298,15 +309,16 @@ async function getPrice(price_ID, symbol) {
298309
}
299310
}
300311

301-
getPrice(PRICE_IDS[0], 'BTC/USD:');
302-
312+
getPrice(PRICE_IDS[0], "BTC/USD:");
303313
```
304314

305315
<center>
306-
[See full example on GitHub](https://github.com/near-examples/near-js/blob/main/node-js/oracle-example/pyth-oracle-view.js)
316+
[See full example on
317+
GitHub](https://github.com/near-examples/near-js/blob/main/node-js/oracle-example/pyth-oracle-view.js)
307318
</center>
308319

309320
---
321+
310322
## On-Chain Prices
311323

312324
For on-chain price interactions, see the [example contract][] in the

0 commit comments

Comments
 (0)