Last active
August 24, 2021 13:53
-
-
Save this-post/bbf05ff256db361b763eca274242c831 to your computer and use it in GitHub Desktop.
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
const InputDataDecoder = require('ethereum-input-data-decoder') | |
let abi = [{"inputs":[{"internalType":"address","name":"_sender","type":"address"},{"internalType":"uint256","name":"_amount0","type":"uint256"},{"internalType":"uint256","name":"_amount1","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"pancakeCall","outputs":[],"stateMutability":"nonpayable","type":"function"}] | |
let data = "0x84800812000000000000000000000000cc598232a75fb1b361510bce4ca39d7bc39cf498000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000deb41b5d63a9bb93b4f4000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000" | |
let decoder = new InputDataDecoder(abi) | |
result = decoder.decodeData(data) | |
// https://stackoverflow.com/questions/34309988/byte-array-to-hex-string-conversion-in-javascript | |
function toHexString(byteArray) { | |
return Array.from(byteArray, function(byte) { | |
return ('0' + (byte & 0xFF).toString(16)).slice(-2); | |
}).join('') | |
} | |
console.log(`Argument 1 (address): ${result['inputs'][0]}`) | |
console.log(`Argument 2 (uint256): ${result['inputs'][1].toString()}`) | |
console.log(`Argument 3 (uint256): ${result['inputs'][2].toString()}`) | |
console.log(`Argument 4 (bytes): ${toHexString(result['inputs'][3])}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment