I am working on an ERC827 contract invocation through metamask. For ERC827 transfer method require an additional 'data' argument. Since encodeABI()supports only synchronous invocation, metamask throws error. Is there a way to workaround this problem?

my contract invocation code is something like below.

let erc827_abi = { contract abi}
let service_abi = {contract abi}
var erc827_address = '0x9df5e31a1e5de828254d535d5c9b514d513316e8'
var service_crt_address = '0x1ce94a12f58b0b9b39d0a9f1520878a07d9a72e8' 
var user_address = web3.eth.accounts[0]

const erc827contractInstance = web3.eth.contract(erc827_abi).at(erc827_address);
const servicecontractInstance = web3.eth.contract(service_abi).at(service_crt_address);

//encodeABI() is the call which fails.

const sdata = servicecontractInstance.bookService(args.servicename,user_address,args.customername,args.servicetype,args.value,args.transaction_type,args.account_number).encodeABI(function(error, result){
console.log("encoded ABI is",sdata)

erc827contractInstance.transferFrom(user_address,testadd_2,tokensToSend,sdata{from: testadd_2,gas:55000},function (error, result){ //get callback from function which is your transaction key
    } else{

if encodeABI() is invoked like below it works.

const sdata = servicecontractInstance.bookService(args.servicename,user_address,args.customername,args.servicetype,args.value,args.transaction_type,args.account_number).encodeABI();

But unfortunately metamask does not support this.

appreciate any pointers on resolving this.

Thanks James for your response. Please see the error information. not sure this is the one you are looking for.

inpage.js:1 Uncaught Error: The MetaMask Web3 object does not support synchronous methods like eth_sendTransaction without a callback parameter. See https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#dizzy-all-async---think-of-metamask-as-a-light-client for details.
    at MetamaskInpageProvider.send (inpage.js:1)
    at s.send (inpage.js:1)
    at n.e [as sendTransaction] (inpage.js:1)
    at u.sendTransaction (inpage.js:1)
    at u.execute (inpage.js:1)
    at HTMLDivElement.<anonymous> (:formatted:1767)
MetamaskInpageProvider.send @ inpage.js:1
s.send @ inpage.js:1
e @ inpage.js:1
u.sendTransaction @ inpage.js:1
u.execute @ inpage.js:1
(anonymous) @ :formatted:1767
  • Could you provide a stack trace?
    – James_pic
    Commented May 30, 2018 at 15:38
  • I think the problem is that you're calling contract.myMethod(params).encodeABI(), rather than contract.myMethod.encodeABI(params), but I'll need to double-check. Also, it looks like you're using the Web3 instance injected by MetaMask. Don't do that.
    – James_pic
    Commented May 30, 2018 at 16:26

1 Answer 1


In Web3 0.20 (which, if you're using the Web3 injected by MetaMask, is what you're using - BTW, don't do that), myContract.myMethod(params) will make a transaction with those parameters. Then myContract.myMethod(params).encodeABI() would attempt to call encodeABI on the result of that transaction, which is probably not what you want, not least because encodeABI doesn't exist in Web3 0.20.

In Web3 0.20, the equivalent encantation would be myContract.myMethod.getData(params).

  • 2
    In web3 v0.20 .encodeABI() was named .getData().
    – Ismael
    Commented May 30, 2018 at 16:34
  • 'don't do that' why?
    – Henk
    Commented May 30, 2018 at 16:56
  • MetaMask themselves recommend against using the bundled Web3: github.com/MetaMask/faq/blob/master/DEVELOPERS.md. Historically, Web3 has had breaking changes from one release to the next, and it means the code you're running is different to the code you've tested. They've deprecated the bundled Web3 instance, and plan to remove it soon - indeed Mist (an alternative to MetaMask) already has.
    – James_pic
    Commented May 30, 2018 at 22:30
  • Thanks James and Ismael. James, as you suggested myContract.myMethod.getData(params) works. I am relatively new to this. So your suggestion is use own instance of web3 or other libraries other than the injected one?
    – Shibu
    Commented May 31, 2018 at 8:24
  • Yes, that is generally the best approach. If you want to stick with Web3 0.20, use the instructions at github.com/ethereum/wiki/wiki/JavaScript-API#adding-web3. Most alternative libraries will have similar instructions in their "Getting Started" section.
    – James_pic
    Commented May 31, 2018 at 8:58

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.