@@ -29,50 +29,51 @@ import { fillPythUpdate, multicall3Bundler } 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- });
32+ const PYTH_CONTRACT_OP_SEPOLIA = " 0x0708325268df9f66270f1401206434524814508b"
33+ const HERMES_ENDPOINT = " https://hermes.pyth.network"
3734
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- );
35+ const client = createPublicClient ({
36+ chain: optimismSepolia ,
37+ transport: http (" YOUR_RPC_ENDPOINT" ),
38+ });
5339
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- );
40+ // Fill Pyth update data using "trace_callMany"
41+ const pythUpdate = await fillPythUpdate (
42+ client ,
43+ {
44+ to: " 0x3252c2F7962689fA17f892C52555613f36056f22" ,
45+ data: " 0xd09de08a" , // Your transaction calldata
46+ from: " 0x78357316239040e19fC823372cC179ca75e64b81" ,
47+ },
48+ PYTH_CONTRACT_OP_SEPOLIA
49+ HERMES_ENDPOINT ,
50+ {
51+ method: " trace_callMany"
52+ maxIter : 5 ,
53+ },
54+ );
7055
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- }
56+ // Fill Pyth update data using "debug_traceCall"
57+ const pythUpdateWithDebugTrace = await fillPythUpdate (
58+ client ,
59+ {
60+ to: " 0x3252c2F7962689fA17f892C52555613f36056f22" ,
61+ data: " 0xd09de08a" , // Your transaction calldata
62+ from: " 0x78357316239040e19fC823372cC179ca75e64b81" ,
63+ },
64+ " 0x0708325268df9f66270f1401206434524814508b" , // Pyth contract address
65+ " https://hermes.pyth.network" , // Hermes endpoint
66+ {
67+ method: " debug_traceCall" ,
68+ bundler: multicall3Bundler // or any function that takes a PythUpdate and a CallRequest and produces a CallRequest
69+ maxIter : 5 ,
70+ },
71+ );
72+
73+ if (pythUpdate ) {
74+ console .log (" Pyth update needed:" , pythUpdate );
75+ // Bundle the calls together, or pass the pythUpdate.updateData to your contract.
76+ } else {
77+ console .log (" No Pyth data needed for this transaction" );
7778}
78- ```
79+ ```
0 commit comments