Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
arround freeze sendTransaction.
const pify = require('pify')
async function queueTransaction(from, to, value, nonce, gasLimit, data) {
const response = await pify(web3.currentProvider.send)({
jsonrpc: "2.0",
method: "eth_sendTransaction",
id: new Date().getTime(),
params: [
from: from,
to: to,
gas: gasLimit,
value: value,
nonce: nonce,
data: data
if (response.error) {
throw new Error(response.error.message);
return response.result;
it('multi transfer in same block', async () => {
web3.extend({property: 'mine', methods: [{ name: 'start', call: 'miner_start', params:0}]})
web3.extend({property: 'mine', methods: [{ name: 'stop', call: 'miner_stop', params:0}]})
const instance = await
const beforeBlock = await web3.eth.getBlockNumber()
const nonce = await web3.eth.getTransactionCount(accounts[0])
await web3.mine.stop()
const tx1_data = instance.contract.methods.transfer(accounts[1], 100).encodeABI()
const tx2_data = instance.contract.methods.transfer(accounts[2], 100).encodeABI()
// queued tx1
await queueTransaction(owner, Instance.address, 0, nonce, gas, tx1_data)
// queued tx2
await queueTransaction(owner, Instance.address, 0, nonce+1, gas, tx2_data)
await web3.mine.start()
const afterBlock = await web3.eth.getBlockNumber();
assert.equal(beforeBlock+1, afterBlock) // block increase just +1.
assert.equal(await Instance.balanceOf(accounts[1]), 100)
assert.equal(await Instance.balanceOf(accounts[2]), 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment