0

Running something simple as this:

Contract = new web3.eth.Contract(this.contractABI, this.contractAddress)
Contract.methods.transfer(toAccount.address, transfferAmount).encodeABI()

Gives me following error:

ERROR TypeError: _this.tokenContract.methods.transfer is not a function

What could I be doing wrong? I have showed the Contract variable on the console, and it in fact does not have "transfer" in its methods property.

  • check you abi. Do you see a transfer function in you abi? – Prashant Prabhakar Singh Jan 11 at 8:12
  • @PrashantPrabhakarSingh Thank you for your help. I just checked and no, I do not see a transfer function in my ABI. The ABI that I am using is actually some random ABI that I found on the internet, because I thought all ERC-20 token's ABI's are the same. Are they not? The custom token I am trying to transfer is this: ropsten.etherscan.io/token/… If not all ABI's are the same, where can I find the ABI for my token? – dshukertjr Jan 11 at 9:54
  • You can not call transfer method if that does not exist in ABI. You need to get the ABI of the contract, which has transfer method.. ;-) – Yogesh - EtherAuthority.io Jan 11 at 9:57
  • @Yogesh-EtherAuthority.io Thank you for stopping by to help me. How can I get the ABI of the contract? I could not find it on etherscan. – dshukertjr Jan 11 at 10:02
  • If your code is verified, then you will see that in etherscan.. or if you are using your remix, you will find it in compile section. If you use truffle, you will find that in build folder – Yogesh - EtherAuthority.io Jan 11 at 12:00
2

If you are using web3 v0.x then you can send transaction by following:

// creation of contract object
var MyContract = web3.eth.contract(abi);
// initiate contract for an address
var myContractInstance = MyContract.at(contractAddress);
// send a transaction to a function
myContractInstance.myStateChangingMethod('someParam1', {value: xxx, gas: xxxx});

If you are using web3 v1.x then you can send transaction by following:

var myContractInstance = new web3.eth.Contract(abi, contractAddress);
myContractInstance.transfer('some params')
   .send({
           from: account address, 
           gas: 0x00, 
           gasPrice: 0x00
        }).then(receipt=> {consol.log(receipt)});

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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