Skip to content

Instantly share code, notes, and snippets.

@kumavis
Created November 22, 2019 05:26
Show Gist options
  • Save kumavis/db5f5d7768c857d6c7b24f5e78b2cd41 to your computer and use it in GitHub Desktop.
Save kumavis/db5f5d7768c857d6c7b24f5e78b2cd41 to your computer and use it in GitHub Desktop.
batch tx polyfill idea
const provider = polyfillJsonRpcBatchAsBatchTx(inpageProvider)
function polyfillJsonRpcBatchAsBatchTx (oldProvider) {
const newProvider = { sendAsync }
return newProvider
function sendAsync (req, cb) {
if (Array.isArray(req)) {
const shouldBatch = req.every(req => req.method === 'eth_sendTransaction')
if (!shouldBatch) {
// procede normally
return oldProvider.sendAsync(req, cb)
}
// do as a batch
const newReq = {
method: 'wallet_batchTx',
params: req.map(entry => entry.params[0]),
}
return oldProvider.sendAsync(newReq, cb)
} else {
// procede normally
return oldProvider.sendAsync(req, cb)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment