web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

Feature Request : New function to decodeParameters with getTransaction

Open cokia opened this issue 5 years ago • 12 comments

"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.

cokia avatar May 31 '20 15:05 cokia

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

cgewecke avatar Jun 01 '20 13:06 cgewecke

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

cokia avatar Jun 02 '20 22:06 cokia

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

@cgewecke

cokia avatar Jun 10 '20 00:06 cokia

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

NicolasKritter avatar Jun 12 '20 09:06 NicolasKritter

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

cgewecke avatar Jun 12 '20 13:06 cgewecke

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

GregTheGreek avatar Jun 29 '20 18:06 GregTheGreek

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.

cokia avatar Jul 18 '20 05:07 cokia

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.

github-actions[bot] avatar Aug 18 '20 00:08 github-actions[bot]

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.

github-actions[bot] avatar Oct 17 '20 01:10 github-actions[bot]

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.

What I don't understand about this example is that technically the JSON interface shouldn't be necessary as the function and its types are technically encoded in the input data of a transaction. I'm actually a bit surprised that this functionality doesn't exist in web3.js

TimDaub avatar Oct 20 '22 15:10 TimDaub

@TimDaub you're right. it dosen't needs JSON interface.

I think this is a very necessary method, and someone to continue to pull request what I haven't done.

cokia avatar Oct 24 '22 16:10 cokia

Hey @cokia, we will not be implementing this for v1, but we updated it for consideration for a v4 feature request.

mconnelly8 avatar Jun 21 '23 17:06 mconnelly8