Code Monkey home page Code Monkey logo

multicall-decode's Introduction

multicall-decode

EVM multicall calldata decoder

Install

npm install multicall-decode

Basic Usage : with a direct abi encoded bytes[]

const { decodeRaw } = require("multicall-decode");
const CALLDATA =
  "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008413ead5620000000000000000000000005c8cd1c2f2997f7a041026cc29de8177b4c6d8ec00000000000000000000000089e54f174ca5ff39cf53ab58004158e2ca012eac0000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000035f2482336c0d4c2ba6e94faa1d66f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000164883164560000000000000000000000005c8cd1c2f2997f7a041026cc29de8177b4c6d8ec00000000000000000000000089e54f174ca5ff39cf53ab58004158e2ca012eac0000000000000000000000000000000000000000000000000000000000000bb8fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2764c00000000000000000000000000000000000000000000000000000000000a11a8000000000000000000000000000000000000000000000000000000e8d4a510000000000000000000000000000000000000000000000a56d35c029fd16645e079000000000000000000000000000000000000000000000000000000e840308c030000000000000000000000000000000000000000000a503344abc0fbe23670910000000000000000000000005a2b5cb4ce921abd65f0c66c2c839894bfc2076c000000000000000000000000000000000000000000000000000000006244356a00000000000000000000000000000000000000000000000000000000";
  
async function main() {
  console.log(await decodeRaw(CALLDATA));
}

main();

//[
//  [
//    {
//      signature: 'mint((address,address,uint24,int24,int24,uint256,uint256,uint256,uint256,address,uint256))',
//      _id: 0,
//      parameters: [Array],
//      valid: true
//    }
//  ],
//  [
//    {
//      signature: 'createAndInitializePoolIfNecessary(address,address,uint24,uint160)',
//      _id: 0,
//      parameters: [Array],
//      valid: true
//    }
//  ]
//]

Basic Usage : with an abi decoded array of bytes

const { decodeCalls } = require("multicall-decode");
const Web3 = require('web3');
const CALLDATA =
  "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008413ead5620000000000000000000000005c8cd1c2f2997f7a041026cc29de8177b4c6d8ec00000000000000000000000089e54f174ca5ff39cf53ab58004158e2ca012eac0000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000035f2482336c0d4c2ba6e94faa1d66f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000164883164560000000000000000000000005c8cd1c2f2997f7a041026cc29de8177b4c6d8ec00000000000000000000000089e54f174ca5ff39cf53ab58004158e2ca012eac0000000000000000000000000000000000000000000000000000000000000bb8fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2764c00000000000000000000000000000000000000000000000000000000000a11a8000000000000000000000000000000000000000000000000000000e8d4a510000000000000000000000000000000000000000000000a56d35c029fd16645e079000000000000000000000000000000000000000000000000000000e840308c030000000000000000000000000000000000000000000a503344abc0fbe23670910000000000000000000000005a2b5cb4ce921abd65f0c66c2c839894bfc2076c000000000000000000000000000000000000000000000000000000006244356a00000000000000000000000000000000000000000000000000000000";
  
const web3 = new Web3();

async function main() {
  const calls = web3.eth.abi.decodeParameter("bytes[]", CALLDATA);
  console.log(await decodeCalls(calls));
}

main();

//[
//  [
//    {
//      signature: 'mint((address,address,uint24,int24,int24,uint256,uint256,uint256,uint256,address,uint256))',
//      _id: 0,
//      parameters: [Array],
//      valid: true
//    }
//  ],
//  [
//    {
//      signature: 'createAndInitializePoolIfNecessary(address,address,uint24,uint160)',
//      _id: 0,
//      parameters: [Array],
//      valid: true
//    }
//  ]
//]

Input

The input of decodeRaw is expected to be an abi encoded hex string representing a bytes[].

The input of decodeCalls is expected to be an abi decoded array of bytes.

Output

The output is an array containing one set of candidates for each call embedded in the input.

Each set of candidates is itself an array of objects, each object describes a candidate call :

Property Type Description Optional
signature string The signature of the candidate function No
_id number The id of the candidate function No
parameters array An array of Parameter objects describing the function's input Yes
valid boolean A boolean value stating the validity of this candidate. No

If decoding was successfull, the parameters of a valid candidate are present in the parameters array :

Property Description
type The type of the parameter (e.g., address)
_id The ID of the parameter / Index in the function's signature
value The value of the parameter as returned by Web3

multicall-decode's People

Contributors

hroussille avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

alexblack772

multicall-decode's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.