All Projects → miguelmota → Ethereum Input Data Decoder

miguelmota / Ethereum Input Data Decoder

Licence: mit
Ethereum smart contract transaction input data decoder

Programming Languages

javascript
184084 projects - #8 most used programming language
solidity
1140 projects

Projects that are alternatives of or similar to Ethereum Input Data Decoder

Kethereum
Kotlin library for Ethereum
Stars: ✭ 161 (-33.47%)
Mutual labels:  ethereum, library
Web3swift
Elegant Web3js functionality in Swift. Native ABI parsing and smart contract interactions.
Stars: ✭ 237 (-2.07%)
Mutual labels:  ethereum, smart-contracts
Dasp
The Decentralized Application Security Project
Stars: ✭ 166 (-31.4%)
Mutual labels:  ethereum, smart-contracts
Php Ip Tools
Useful tools for IP manipulations
Stars: ✭ 152 (-37.19%)
Mutual labels:  utility, library
Flint
The Flint Programming Language for Smart Contracts
Stars: ✭ 228 (-5.79%)
Mutual labels:  ethereum, smart-contracts
Ffmediatoolkit
FFMediaToolkit is a cross-platform video decoder/encoder library for .NET that uses FFmpeg native libraries. It supports video frames extraction, reading stream metadata and creating videos from bitmaps in any format supported by FFmpeg.
Stars: ✭ 156 (-35.54%)
Mutual labels:  library, decoder
Paco
Small utility library for coroutine-driven asynchronous generic programming in Python 3.4+
Stars: ✭ 198 (-18.18%)
Mutual labels:  utility, library
Sablier
The protocol for real-time finance on the Ethereum blockchain
Stars: ✭ 147 (-39.26%)
Mutual labels:  ethereum, smart-contracts
Blockchain Stuff
Blockchain and Crytocurrency Resources
Stars: ✭ 2,549 (+953.31%)
Mutual labels:  ethereum, smart-contracts
Erc20 Generator
Create an ERC20 Token for FREE in less than a minute with the most used Smart Contract Generator for ERC20 Token. No login. No setup. No coding required.
Stars: ✭ 202 (-16.53%)
Mutual labels:  ethereum, smart-contracts
Weihanli.common
common tools,methods,extension methods etc... .net 常用工具类,公共方法,常用扩展方法等,基础类库
Stars: ✭ 152 (-37.19%)
Mutual labels:  utility, library
Merkletreejs
🌱 Construct Merkle Trees and verify proofs in JavaScript.
Stars: ✭ 238 (-1.65%)
Mutual labels:  ethereum, smart-contracts
Set Protocol Contracts
🎛 Set Protocol Smart Contracts
Stars: ✭ 151 (-37.6%)
Mutual labels:  ethereum, smart-contracts
Ico Contracts
Ethereum smart contracts that have been used during successful ICOs
Stars: ✭ 160 (-33.88%)
Mutual labels:  ethereum, smart-contracts
Ebtc
eBitcoin (eBTC) is an ERC20 token. Its primary utility is to provide an easy & fast payment solution. Its edge over other tokens is that it is capable of sending up to 255 payments in a single transaction.
Stars: ✭ 149 (-38.43%)
Mutual labels:  ethereum, smart-contracts
Txeh
Go library and CLI utilty for /etc/hosts management.
Stars: ✭ 181 (-25.21%)
Mutual labels:  utility, library
Peatiocryptoexchange
An open-source Crypto-Currency exchange. Peatio v3.0 Coming Soon !
Stars: ✭ 141 (-41.74%)
Mutual labels:  ethereum, smart-contracts
Coinbasepro Csharp
The unofficial .NET/C# client library for the Coinbase Pro/GDAX API
Stars: ✭ 143 (-40.91%)
Mutual labels:  ethereum, library
Swc Registry
Smart Contract Weakness Classification and Test Cases
Stars: ✭ 200 (-17.36%)
Mutual labels:  ethereum, smart-contracts
Remix Project
Remix is a browser-based compiler and IDE that enables users to build Ethereum contracts with Solidity language and to debug transactions.
Stars: ✭ 225 (-7.02%)
Mutual labels:  ethereum, smart-contracts


logo


ethereum-input-data-decoder

Ethereum smart contract transaction input data decoder

License Build Status dependencies Status NPM version PRs Welcome

Demo

https://lab.miguelmota.com/ethereum-input-data-decoder

Install

npm install ethereum-input-data-decoder

Getting started

Pass ABI file path to decoder constructor:

const InputDataDecoder = require('ethereum-input-data-decoder');
const decoder = new InputDataDecoder(`${__dirname}/abi.json`);

Alternatively, you can pass ABI array object to constructor;

const abi = [{ ... }]
const decoder = new InputDataDecoder(abi);

example abi

Then you can decode input data:

const data = `0x67043cae0000000000000000000000005a9dac9315fdd1c3d13ef8af7fdfeb522db08f020000000000000000000000000000000000000000000000000000000058a20230000000000000000000000000000000000000000000000000000000000040293400000000000000000000000000000000000000000000000000000000000000a0f3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c800000000000000000000000000000000000000000000000000000000000000034254430000000000000000000000000000000000000000000000000000000000`;

const result = decoder.decodeData(data);

console.log(result);
{
  "method": "registerOffChainDonation",
  "types": [
    "address",
    "uint256",
    "uint256",
    "string",
    "bytes32"
    ],
    "inputs": [
      <BN: 5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02>,
      <BN: 58a20230>,
      <BN: 402934>,
      "BTC",
      <Buffer f3 df ... 71 c8>
    ],
    "names": [
      "addr",
      "timestamp",
      "chfCents",
      "currency",
      "memo"
    ]
}

Example using input response from web3.getTransaction:

web3.eth.getTransaction(txHash, (error, txResult) => {
  const result = decoder.decodeData(txResult.input);
  console.log(result);
});

Decoding tuple and tuple[] types

Where OrderData is

struct OrderData {
  uint256 amount;
  address buyer;
}

Decoding input to a method someMethod(address,OrderData,OrderData[]) returns data in format

{
  method: 'someMethod',
  types: ['address', '(uint256,address)', '(uint256,address)[]'],
  inputs: [
    '0x81c55017F7Ce6E72451cEd49FF7bAB1e3DF64d0C',
    [100, '0xA37dE6790861B5541b0dAa7d0C0e651F44c6f4D9']
    [[274, '0xea674fdde714fd979de3edf0f56aa9716b898ec8']]
  ],
  names: ['sender', ['order', ['amount', 'buyer']], ['allOrders', ['amount', 'buyer']]]
}
  • In the types field, tuples are represented as a string containing types contained in the tuple
  • In the inputs field, tuples are represented as an array containing values contained in the tuple
  • In the names field, tuples are represented as an array with 2 items. Item 1 is the name of the tuple, item 2 is an array containing the names of the values contained in the tuple.

Decoding Big Numbers

All numbers are returned in big number format to preserve precision.

Here's an example of how to convert the big number to a human readable format.

console.log(result.inputs[0].toString(10)) // "5"
console.log(result.inputs[0].toNumber()) // 55

Please keep in mind that JavaScript only supports numbers up to 64 bits. Solidity numbers can be up to 256 bits, so you run the risk of truncation when casting or having the big number library error out when trying to parse a large number to a JavaScript Number type.

const n = new BN("543534254523452352345234523455")
console.log(n.toString(10)) // "543534254523452352345234523455"
console.log(n.toNumber()) // ERROR!

CLI

Install

npm install -g ethereum-input-data-decoder

Usage

$ ethereum_input_data_decoder --help

  Ethereum smart contract transaction input data decoder

  Usage
    $ ethereum_input_data_decoder [flags] [input]

  Options
    --abi, -a  ABI file path
    --input, -i Input data file path

  Examples
    $ ethereum_input_data_decoder --abi token.abi --input data.txt
    $ ethereum_input_data_decoder --abi token.abi "0x23b872dd..."

Example

Pass ABI file and input data as file:

$ ethereum_input_data_decoder --abi abi.json --input data.tx

method   registerOffChainDonation

address  addr       0x5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02
uint256  timestamp  1487012400
uint256  chfCents   4204852
string   currency   BTC
bytes32  memo       0xf3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c8

Pass ABI file and input data as string:

$ ethereum_input_data_decoder --abi abi.json 0x67043cae0...000000

method   registerOffChainDonation

address  addr       0x5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02
uint256  timestamp  1487012400
uint256  chfCents   4204852
string   currency   BTC
bytes32  memo       0xf3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c8

You can also pipe the input data:

$ cat data.txt | ethereum_input_data_decoder --abi abi.json

method   registerOffChainDonation

address  addr       0x5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02
uint256  timestamp  1487012400
uint256  chfCents   4204852
string   currency   BTC
bytes32  memo       0xf3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c8

Test

npm test

Development

  1. Clone repository:
git clone [email protected]:miguelmota/ethereum-input-data-decoder.git

cd ethereum-input-data-decoder/
  1. Install dependencies:
npm install
  1. Make changes.

  2. Run tests:

npm test
  1. Run linter:
npm run lint

Contributing

Pull requests are welcome!

For contributions please create a new branch and submit a pull request for review.

Many thanks to all the contributors for making this a better library for everyone 🙏

FAQ

  • Q: How can I retrieve the ABI?

    • A: You can generate the ABI from the solidity source files using the Solidity Compiler.

      solc --abi MyContract.sol -o build
      
  • Q: Can this library decode contract creation input data?

    • A: Yes, it can decode contract creation input data.
  • Q: Does this library support ABIEncoderV2?

    • A: Yes, but it's buggy. Please submit a bug report if you encounter issues.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].