7

I want to call a function of the contract, something like this -

module.exports.transfer = function(to,value,){ 
   return token.methods.transfer.getData(to, value);
}

But I am facing the error

token.methods.transfer.getData is not a function

How do i resolve it , is getData() deprecated or their is any other way to get the data of function with desired arguments ?

web3 version - 1.0 beta

Thanks

2 Answers 2

7

For web3 1.0 beta you should use encodeABI, from the documentation:

myContract.methods.myMethod(123).encodeABI();
0
0

for web3 1.2.1(new release) you should use it like:

    contract_interfact.methods.methodName().call({from:"address"},(err,res) => {
       ...
})


    contract_interfact.methods.methodName(arguments).send({from:"address"},(err,res) => {
        ...
})

Your Answer

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

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