Created
November 17, 2020 11:42
-
-
Save johngrantuk/24c5576549e4501489516e31ccf46160 to your computer and use it in GitHub Desktop.
Example showing how to get tx info from tx hash using ethers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example showing how to get tx info from tx hash using ethers.js | |
// Add .env file with INFURA key. Free key from: https://infura.io/ | |
require('dotenv').config(); | |
import { JsonRpcProvider } from '@ethersproject/providers'; | |
import { Interface } from '@ethersproject/abi'; | |
async function getTransactionDetails(){ | |
let txHash = `0x4b55c0b756dbfbcd997e94b98698241299d16d5297cd17aa463d280d215a1f52`; // Example tx hash from Etherscan | |
console.log(`getTransactionDetails: ${txHash}`); | |
const provider = new JsonRpcProvider( | |
`https://mainnet.infura.io/v3/${process.env.INFURA}` // If running this example make sure you have a .env file saved in root DIR with INFURA=your_key | |
); | |
let tx = await provider.getTransaction(txHash); | |
// console.log(tx); // Have a look at this to get familiar with what it shows | |
const proxyArtifact = require('./abi/ExchangeProxy.json'); | |
const iface = new Interface(proxyArtifact.abi); | |
const txParsed = iface.parseTransaction({ data: tx.data }); | |
console.log(txParsed.args.swapSequences); // Start looking at parsing the pools used from this. Some will have a single pool others will have multipool so check both work ok. | |
console.log(txParsed.functionFragment.name); // i.e. multihopBatchSwapExactOut | |
} | |
getTransactionDetails(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment