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

Satyam Agrawal
  • 775
  • 1
  • 8
  • 19

2 Answers2

7

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

myContract.methods.myMethod(123).encodeABI();
Ismael
  • 30,570
  • 21
  • 53
  • 96
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) => {
        ...
})
cryptoKTM
  • 431
  • 1
  • 3
  • 15