@@ -25,54 +25,53 @@ The `fillPythUpdate` function helps you automatically determine what Pyth price
2525This function uses the ` trace_callMany ` method by default but can be used with ` debug_traceCall ` and a bundler as well. See the example below for more information.
2626
2727``` typescript
28- import { fillPythUpdate , multicall3Bundler } from " @pythnetwork/pyth-evm-js" ;
28+ import { fillPythUpdate , multicall3Bundler , CallRequest } from " @pythnetwork/pyth-evm-js" ;
2929import { createPublicClient , http } from " viem" ;
3030import { optimismSepolia } from " viem/chains" ;
3131
32- async function example() {
33- const client = createPublicClient ({
34- chain: optimismSepolia ,
35- transport: http (" YOUR_RPC_ENDPOINT" ),
36- });
37-
38- // Fill Pyth update data using "trace_callMany"
39- const pythUpdate = await fillPythUpdate (
40- client ,
41- {
42- to: " 0x3252c2F7962689fA17f892C52555613f36056f22" ,
43- data: " 0xd09de08a" , // Your transaction calldata
44- from: " 0x78357316239040e19fC823372cC179ca75e64b81" ,
45- },
46- " 0x0708325268df9f66270f1401206434524814508b" , // Pyth contract address
47- " https://hermes.pyth.network" , // Hermes endpoint
48- {
49- method: " trace_callMany"
50- maxIter : 5 ,
51- },
52- );
53-
54- // Fill Pyth update data using "debug_traceCall"
55- const pythUpdateWithDebugTrace = await fillPythUpdate (
56- client ,
57- {
58- to: " 0x3252c2F7962689fA17f892C52555613f36056f22" ,
59- data: " 0xd09de08a" , // Your transaction calldata
60- from: " 0x78357316239040e19fC823372cC179ca75e64b81" ,
61- },
62- " 0x0708325268df9f66270f1401206434524814508b" , // Pyth contract address
63- " https://hermes.pyth.network" , // Hermes endpoint
64- {
65- method: " debug_traceCall" ,
66- bundler: multicall3Bundler // or any function that takes a PythUpdate and a CallRequest and produces a CallRequest
67- maxIter : 5 ,
68- },
69- );
70-
71- if (pythUpdate ) {
72- console .log (" Pyth update needed:" , pythUpdate );
73- // Bundle the calls together, or pass the pythUpdate.updateData to your contract.
74- } else {
75- console .log (" No Pyth data needed for this transaction" );
76- }
32+ const PYTH_CONTRACT_OP_SEPOLIA = " 0x0708325268df9f66270f1401206434524814508b"
33+ const HERMES_ENDPOINT = " https://hermes.pyth.network"
34+
35+ const client = createPublicClient ({
36+ chain: optimismSepolia ,
37+ transport: http (" YOUR_RPC_ENDPOINT" ),
38+ });
39+
40+ const call: CallRequest = {
41+ to: " 0x3252c2F7962689fA17f892C52555613f36056f22" ,
42+ data: " 0xd09de08a" , // Your transaction calldata
43+ from: " 0x78357316239040e19fC823372cC179ca75e64b81" ,
44+ };
45+
46+ // Fill Pyth update data using "trace_callMany"
47+ const pythUpdate = await fillPythUpdate (
48+ client ,
49+ call ,
50+ PYTH_CONTRACT_OP_SEPOLIA ,
51+ HERMES_ENDPOINT ,
52+ {
53+ method: " trace_callMany" ,
54+ maxIter: 5 ,
55+ },
56+ );
57+
58+ // Fill Pyth update data using "debug_traceCall"
59+ const _pythUpdateWithDebugTraceCall = await fillPythUpdate (
60+ client ,
61+ call ,
62+ PYTH_CONTRACT_OP_SEPOLIA ,
63+ HERMES_ENDPOINT ,
64+ {
65+ method: " debug_traceCall" ,
66+ bundler: multicall3Bundler , // or any function that takes a PythUpdate and a CallRequest and produces a CallRequest
67+ maxIter: 5 ,
68+ },
69+ );
70+
71+ if (pythUpdate ) {
72+ console .log (" Pyth update needed:" , pythUpdate );
73+ // Bundle the calls together, or pass the pythUpdate.updateData to your contract.
74+ } else {
75+ console .log (" No Pyth data needed for this transaction" );
7776}
78- ```
77+ ```
0 commit comments