Giter Club home page Giter Club logo

abiencoder's Introduction

ABI Encoder

https://abi.hashex.org

Description

Free ABI encoder online service that allows you to encode your Solidity contract’s functions and constructor arguments.

ABI itself is the description of the code interface. It’s a way for the contracts to interact within an ecosystem as well as contract-to-contract.

Smart contract ABI parsing is required for verifying the contract on Etherscan or making a transaction to call a method, for example for a Timelock contract. For most actions regarding this code, you would require a special tool, and the arguments have to be encoded in a specific way. HashEx tool does it automatically, free, and doesn’t involve downloading any extra applications.

Code itself is used in the byte format, so it’s harder to decode it correctly. For easy interactions with said code, HashEx has created its ABI decoder. An additional tool allows you to manually enter the values for the parameters.

Supported types

  • uint8..256
  • uint[]8..256
  • bytes8..32
  • bytes[]8..32
  • address
  • address[]
  • string
  • bool
  • bool[]
  • tuple (supports Struct from ABI)

Feel free to open PR to add new types.

How to use

Manually enter

  1. Enter signature of function (Example: transferFrom(adress, uint)) manually with selecting "your function" option or use the "constructor" option.
  2. Add arguments, select the correct types.
  3. Fill the arguments.
  4. Encoded data will appear in the text area under the function. Click "Copy" button and paste it where ever you want.

image

Using ABI autoparse

  1. Enter your contract ABI into the text field and click "Parse" button.
  2. Select the function or constructor from the parsed list.
  3. Fill the arguments.
  4. Encoded data will appear in the text area under the function. Click "Copy" button and paste it where ever you want.

image

How to encode struct arguments

Encode struct argument with existing ABI

  1. Enter your contract ABI into the text field and click "Parse" button.
  2. Select the function or constructor from the parsed list which has struct argument.
  3. Enter struct value according to example. Use Struct description under input as a hint.
  4. Encoded data will appear in the text area under the function. Click "Copy" button and paste it where ever you want.

image

Encode struct argument without existing ABI

  1. Describe your function or constructor using ABI template.

Function example:

    contract MyCustomContract {
        struct MyCustomStruct {
            uint256 number;
            address to;
        }
        constructor(MyCustomStruct memory _myCustomStruct) {
            // some logic
        }
        function myCustomFunction(MyCustomStruct memory _myCustomStruct) {
            // some logic
        }
    }

ABI example:

    [{
        "type": "constructor",
        "name": "",
        "inputs": [{
            "components": [{ 
                "type": "uint256",
                "name": "number"
            },{
                "type": "string",
                "name": "note"
            }],
            "internalType": "struct MyCustomContract.MyCustomStruct",
            "type": "tuple",
            "name": "_myCustomStruct"
        }]
    },{
        "type": "function",
        "name": "myCustomFunction",
        "inputs": [{
            "components": [{ 
                "type": "uint256",
                "name": "number"
            },{
                "type": "string",
                "name": "note"
            }],
            "internalType": "struct MyCustomContract.MyCustomStruct",
            "name": "_myCustomStruct",
            "type": "tuple"
        }]
    }]
"components": [...],    // `components` field is for Struct fields description
"type": "tuple",        // this type means you want to use Struct as argument

then follow the steps as if you have ABI to parse.

How to run

Install dependencies

npm install or yarn

Start project

npm start or yarn start

…and open http://localhost:3000 in your web browser.

Contributing

The site is powered by CRA(Create React App) using React.js and ethers.js.

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. Submit a Pull request so that we can review your changes

NOTE: Be sure to merge the latest from "upstream" before making a pull request!

Licenses

MIT

abiencoder's People

Contributors

masquel avatar nareknk avatar owtmpatrick avatar shuklaayush avatar staslopatiev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

abiencoder's Issues

constructor name should be undefined in README example

According to the abi-spec:

Constructor and fallback function never have `name` or `outputs`

but the ABI example defines a constructor with name of empty string:

"type": "constructor",
"name": "",

The name value should be null or the name key should not be present at all.

Method ID incorrect and wrong encoded content

Here's the abi:verifier.abi
The method id for verifyTx should be 0x43cd76fc while the online encoder gave me 0xc7f48250.
And also my input is:

[
[
"0x0e80ca8906f6387652a94c97d79c2446708417437743b76b47b567c3e0f6faee",
"0x06de9112ddbf310571c2544efea26794355c36c202f034f9a80f8a98ed783f16"
],
[
[
"0x0949e29be2d68c7ad5e31db0e61c77e982a8b7a446eae46a6df13fffe16aebc2",
"0x12aae077e227a3389ee03a120229c9f5bc6cfb58c81825295777b8782096f2ac"
],
[
"0x208b556687c1459974a72dca91a3142091e19007a065d7fb1088bb06b763db13",
"0x15ed708130cdf189b8f1a0d3ed489f7aee87a9ac27c15c269de5d1b25e9f1df6"
]
],
[
"0x0fd7a5f6827058661ecb4470c5d53282d657db039f430b550da1627548b01ead",
"0x2f9c74bc52ea368da90ced109f1fbf3743cdbe7a9863e1b99dd2772687115ab8"
]
]

and
[
"0x0000000000000000000000009f9afb30acafd9fe7b4362a9e541f725a3d6532f",
"0x00000000000000000000000c781b9fcd7dbd07e1a143b545e9274ef0ccbe7fd0"
]

The correct encoded input should be:
c7f482500e80ca8906f6387652a94c97d79c2446708417437743b76b47b567c3e0f6faee06de9112ddbf310571c2544efea26794355c36c202f034f9a80f8a98ed783f160949e29be2d68c7ad5e31db0e61c77e982a8b7a446eae46a6df13fffe16aebc212aae077e227a3389ee03a120229c9f5bc6cfb58c81825295777b8782096f2ac208b556687c1459974a72dca91a3142091e19007a065d7fb1088bb06b763db1315ed708130cdf189b8f1a0d3ed489f7aee87a9ac27c15c269de5d1b25e9f1df60fd7a5f6827058661ecb4470c5d53282d657db039f430b550da1627548b01ead2f9c74bc52ea368da90ced109f1fbf3743cdbe7a9863e1b99dd2772687115ab80000000000000000000000009f9afb30acafd9fe7b4362a9e541f725a3d6532f00000000000000000000000c781b9fcd7dbd07e1a143b545e9274ef0ccbe7fd0

while the encoder gave me:
c7f482500e80ca8906f6387652a94c97d79c2446708417437743b76b47b567c3e0f6faee06de9112ddbf310571c2544efea26794355c36c202f034f9a80f8a98ed783f160949e29be2d68c7ad5e31db0e61c77e982a8b7a446eae46a6df13fffe16aebc212aae077e227a3389ee03a120229c9f5bc6cfb58c81825295777b8782096f2ac208b556687c1459974a72dca91a3142091e19007a065d7fb1088bb06b763db1315ed708130cdf189b8f1a0d3ed489f7aee87a9ac27c15c269de5d1b25e9f1df60fd7a5f6827058661ecb4470c5d53282d657db039f430b550da1627548b01ead2f9c74bc52ea368da90ced109f1fbf3743cdbe7a9863e1b99dd2772687115ab8000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000020000000000000000000000009f9afb30acafd9fe7b4362a9e541f725a3d6532f00000000000000000000000c781b9fcd7dbd07e1a143b545e9274ef0ccbe7fd0

which contains some redundant data.

Variable is structure type

Hello there,

This tool helps me a lot,
I wanna know how to encode a function which has a variable of structure type.

Thank you.

Tuple array result in wrong encoding

Given a parameters which is an array of tuple the encoding function produces a wrong result due to input restrictions.
The input field should enforce the user to enter something like this [[1,2,3,4],[5,6,7,8]] but it only takes in the values for one tuple.

This results in a wrong abi encoding for the function.

Inputs:

"0x11223344"
[["0x6b4584A05EB28016aDf0B0A692DD71073Fe4B593","0x123456",0]]
1234
56789
false
3

Generated ABI
0xe910689700000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000004d2000000000000000000000000000000000000000000000000000000000000ddd500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000411223344000000000000000000000000000000000000000000000000000000000000000000000000000000006b4584a05eb28016adf0b0a692dd71073fe4b5930000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000031234560000000000000000000000000000000000000000000000000000000000

Expected ABI
0xe910689700000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000004d2000000000000000000000000000000000000000000000000000000000000ddd50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000041122334400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000006b4584a05eb28016adf0b0a692dd71073fe4b5930000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000031234560000000000000000000000000000000000000000000000000000000000

ABI

[
  {
    "inputs": [
      {
        "internalType": "bytes",
        "name": "",
        "type": "bytes"
      },
      {
        "components": [
          {
            "internalType": "address",
            "name": "to",
            "type": "address"
          },
          {
            "internalType": "uint256",
            "name": "value",
            "type": "uint256"
          },
          {
            "internalType": "bytes",
            "name": "data",
            "type": "bytes"
          }
        ],
        "internalType": "struct IDAO.Action[]",
        "name": "",
        "type": "tuple[]"
      },
      {
        "internalType": "uint64",
        "name": "",
        "type": "uint64"
      },
      {
        "internalType": "uint64",
        "name": "",
        "type": "uint64"
      },
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      },
      {
        "internalType": "enum IMajorityVoting.VoteOption",
        "name": "",
        "type": "uint8"
      }
    ],
    "name": "createVote",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "voteId",
        "type": "uint256"
      }
    ],
    "stateMutability": "pure",
    "type": "function"
  }
]

Doesn't Work

Seems to be a glitch in the code, but after inputing parsed JSON file for ABI w/ constructor arguments, no encoding output is generated. Infact, the encoding generator doesn't have any output for you to copy at all. I tried Edge and Firefox, and used Linux and Windows.

generated abi encoding string is incorrect when contain uint256[M] type

  • I know how to publish contract and verify it
  • I know how to use the tool

My contract constructor arguments has include uint256[3] feeSettings,then I copied form remix abi json and exactly fill every parameter. I copied generated abi code string, but I can not verify my contract.

I did it twice and check every step, but the same result. So I to find only this type argument does not show the right type,I created another contract and remove this type,the part of uint256[3] feeSettings using hard-coding, Wow,it is fine.

So I'm be sure contain argument such as uint256[M]type generate wrong abi encoding.

I hope you can fix it as soon as possible!

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.