1

Does the smart contract containing the function to be encoded have to be deployed first before one can use web3.eth.abi.encodeFunctionSignature() and web3.eth.abi.encodeFunctionCall() for a certain function in the deployed smart contract? Why or why not?

1 Answer 1

2

Having the abi (compiling the smart-contract) is enough (or manually entering the metadata of a function)

web3.eth.abi.encodeFunctionSignature({
    name: 'myMethod',
    type: 'function',
    inputs: [{
        type: 'uint256',
        name: 'myNumber'
    },{
        type: 'string',
        name: 'myString'
    }]
})
> 0x24ee0097
web3.eth.abi.encodeFunctionCall({
    name: 'myMethod',
    type: 'function',
    inputs: [{
        type: 'uint256',
        name: 'myNumber'
    },{
        type: 'string',
        name: 'myString'
    }]
}, ['2345675643', 'Hello!%']);
> 0x24ee0097000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000

If you are not using a compiled ABI but a hardcoded one as above you don't need the contracts to be compiled, you can use as mentioned above.

As an answer, To do these operations smart contract deployment is not essential, compilation is sufficient. These functions are using off-chain encoding and hashing functions to get the relevant output, and these functions do not interact with a smart contract.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.