Git Product home page Git Product logo

tron-tx-decoder's Introduction

tron-tx-decoder

JavaScript Style Guide npm npm bundle size License: MIT

Lightweight utility for decoding function parameters and function output from Tron blocklchain transactions.

  • Minimal dependencies.

  • Decode method name used by specific Transaction Id.

  • Find the input parameter passed to function by Transaction Id.

  • Find the exact output returned from the function by Transaction Id.

  • Built with ethers.js.

Demo: https://tron-decoder.github.io

Installation

npm i tron-tx-decoder

Initialization

const TronTxDecoder = require('tron-tx-decoder');

const decoder = new TronTxDecoder({ mainnet: true });
// { mainnet: false } for testnet

Decode Input:

Decode function input parameters by passing transaction id.

async function decodeTxInput(txId){
    const decodedInput = await decoder.decodeInputById(txId);
    return decodedInput;
}

decodeTxInput("0c739761b34a891b3bbecd528302de827736660d76c62dacf8d3a9ebe7dade08");

Output:

{ 
    methodName: 'submitTheGame',
    inputNames: [ '_betId', 'freshHouseSeed', 'rollResult', '_gameOutcome' ],
    inputTypes: [ 'uint256', 'address', 'uint8', 'uint8' ],
    decodedInput: { 
        '0': BigNumber { _hex: '0x265aa6' },
        '1': '0x8F476d1155E9910A885Cae1c4396BDD392c3883E',
        '2': 11,
        '3': 1,
        _length: 4 
    } 
}

Decode Output:

Decode function outputs by passing transaction id.

async function decodeTxOutput(txId){
    const decodedOutput = await decoder.decodeResultById(txId);
    return decodedOutput;
}

decodeTxOutput("0c739761b34a891b3bbecd528302de827736660d76c62dacf8d3a9ebe7dade08");

Output:

{ 
    methodName: 'submitTheGame',
    outputNames: [ null, null ],
    outputTypes: [ 'uint256', 'uint256' ],
    decodedOutput: { 
        '0': BigNumber { _hex: '0x265aa6' },
        '1': BigNumber { _hex: '0x0615ec20' },
        _length: 2 
    }
}

Decode Revert Message (if any):

Decode function outputs by passing transaction id.

async function decodeRevertMessage(txId){
    const decodedMessage = await decoder.decodeRevertMessage(txId);
    return decodedMessage;
}

decodeRevertMessage("5d6db71f3316a2abdf7f08f97cd42880209ee7344816d404ce865a8679bdb7ae");

Output:

{ 
    txStatus: 'REVERT',
    revertMessage: 'Plot is not currently owned' 
}

BigNumber

Contributing

  • Issues & Pull requests are welcome! Fork, branch, and submit PR.

Changelog

Licence

MIT

tron-tx-decoder's People

Contributors

dependabot[bot] avatar meetsiraja avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tron-tx-decoder's Issues

decoder exception

The decoder fails on this transaction 3fdd7907a87d6fc43a859d58d34329606aaf1f98bac811a033b37e2c9f333290

Just give it a try with https://tron-decoder.github.io/, it shows an error like the following

Error: insufficient data for uint256 type (arg="", coderType="uint256", value="0x", version=4.0.41)

handleInputs is missing

See in the code you have function _handleInputs and handleInputs, but the handleInputs is never declared. My question is how can this work?

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.