1

I have MetaMask working nicely - it's so cool! However, I have a (react) form that gathers in lots of information and creates 14 distinct calls to sendTransaction. Hence, I (currently) get 14 popup windows from MetaMask, asking me to accept those transactions. In fact, exactly like this situation: https://github.com/MetaMask/metamask-plugin/issues/1000

...which I see was 'solved'. So I know it's possible to batch requests, but my question is how? Basically, how should I form the sendAsync call? For instance, say I had these three transactions:

myContractObject.doSomething(name,type)
myContractObject.doSomethingElse(hash)
myContractObject.doSomethingElseEntirely(key)

What would my call to web3.currentProvider.sendAsync look like?

1

You can use the batch request web3 function.

var batch = web3.createBatch();
batch.add(myContractInstance.doSomething(arg1, arg2, {from: account, gas: 4000000}));
batch.add(myContractInstance.doSomethingElse(arg1, arg2, {from: account, gas: 4000000}));
batch.add(myContractInstance.doSomethingElseEntirely(arg1, arg2, {from: account, gas: 4000000}));
batch.execute();

Metamask asks the user for confirmation 3 times:enter image description here

  • But I think sendAsync will only ask for confirmation once.... – glowkeeper Jun 24 '17 at 14:08
  • This still opens multiple tabs on MetaMask. – DanF Jun 24 '17 at 14:22
  • Got it. I only see one tab but multiple confirmations are required for each transaction while it should be one confirmation! – Greg Jeanmart Jun 24 '17 at 15:22
  • @GregJeanmart - thanks - looks like your batch.add solution is correct - as soon as the bug is fixed (see below), I'll accept it as the answer ;) – glowkeeper Jun 24 '17 at 15:45
1

You've caught a legitimate bug in MetaMask, I've opened it on the MetaMask github repository (which is where we track bugs and close them), here:

https://github.com/MetaMask/metamask-plugin/issues/1666

  • Excellent - thanks - I've also added a comment to the MetaMask issue... – glowkeeper Jun 24 '17 at 15:43

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.