Web3.js: Feature Request : New function to decodeParameters with getTransaction

Created on 31 May 2020  路  9Comments  路  Source: ChainSafe/web3.js

"eth.abi.decodeParameters" is a function that decodes an encoded string based on abi, and I think the main use case is decode the input data of the transaction.

So I think it would be nice to create a function called "web3.eth.abi.decodeFunctionCall" and then take the transaction hash and decode the input data.

If many people and maintainer agree to the need for this function, I will pull request this function.

1.x Feature Request work-in-progress

Most helpful comment

@cokia I'm so sorry, this slipped through. Yes, agree this is a good idea.

All 9 comments

@cokia Could you show an example method signature and output for the new method?

eth.abi.decodeFunctionCall(abi,TransactionHash);
>  
{
    'function1param1': 'Hello!%!',
    'function1param2': '234',
    function2param1: 'Hello!%!',
    function2param2: '234'
}

If you are not busy, please leave your comments on this :)

@cgewecke

I had to implement a function like this as we need to parse our own chain, I think this will be a very nice addition to the web3js package

@cokia I'm so sorry, this slipped through. Yes, agree this is a good idea.

@cokia Did you manage to open this pull request? I want to make sure this issue didn't get lost :)

I thought it wouldn't be difficult to make this function, but it didn't work as I thought.

/**
 * Decode function parameter input from transactionhash.
 *
 * @method decodeFunctionCall
 * @param {Array} jsonInterface
 * @param {string} transactionHash
 * @return {Array} array of parameter values
 */

ABICoder.prototype.decodeFunctionCall = (jsonInterface, transactionHash) => new Promise((resolve,rejct) => {
    var _this = this;
    eth.getTransaction(transactionHash).then(function(err,result){
        if(err){
            throw new Error(
                'Returned values aren\'t valid, did it run Out of Gas? ' +
                'You might also see this error if you are not using the ' +
                'correct ABI for the contract you are retrieving data from, ' +
                'requesting data from a block number that does not exist, ' +
                'or querying a node which is not fully synced.'
            );
        }
            const decodedValue = _this.decodeParameters(jsonInterface, result.input);
            resolve(decodedValue)
    });
})

It was my miscalculation that declared as above code, but I thought I could call up the eth sub function.

To call "eth.getTransaction()"you must declare new eth through the provider declared through new web3. But the web3 structure (I think it's problem of I am unskilled to class and constructor) eth need to create and process new constructor with abi, but I think it is not efficient. If anyone can actually implement this idea, please help me.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

Was this page helpful?
0 / 5 - 0 ratings