Skip to content

Instantly share code, notes, and snippets.

@johngrantuk
Created November 17, 2020 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johngrantuk/24c5576549e4501489516e31ccf46160 to your computer and use it in GitHub Desktop.
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
// 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