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){
if(!error)
console.log(result);
else
console.error(error)
});
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
if(!error){
console.log(result);
} else{
console.log(error);
}
});
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
contract.myMethod(params).encodeABI()
, rather thancontract.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.