I'm testing my smart contract on ropsten and I have written an async function that lets me send TRANSACTION
transactions from TRANSACTION
different accounts. For some reason when TRANSACTION > 20
i get caught in the catch statment with a gas exceeds allowance error and i can't figure out why. I have similarly written a function to fund an arbitrary amount of accounts with eth. Litterally all that is done on the smart contract when invoking instance.methods.addSubmission...
is push a uint256
into an array in a mapping(uint256 => uint256[])
async function multipleTx() {
let accounts = await web3.eth.getAccounts()
console.log('Issuing Transactions...')
let totalGasUsed = 0
const promisesArr = []
const sendBlockNumber = await web3.eth.getBlockNumber()
const sendTimeStamp = Date.now()
for (let i = 0; i < TRANSACTIONS; i++) {
console.log('account', i, 'is', accounts[i])
promisesArr.push(
instance.methods.addSubmissionNoCheck(1, 139).send({
from: accounts[i],
gasPrice: 10000000000,
})
)
}
await Promise.all(promisesArr)
.then(async (receipts) => {
let lastBlock = receipts[0].blockNumber
receipts.forEach((receipt) => {
totalGasUsed += receipt.gasUsed
lastBlock =
receipt.blockNumber > lastBlock ? receipt.blockNumber : lastBlock
})
await outputResults(
sendTimeStamp,
totalGasUsed,
sendBlockNumber,
lastBlock
)
})
.catch((error) => {
console.log('multipleTX():', error)
})
}
console output:
multipleTX(): Error: gas required exceeds allowance (8000029) or always failing
transaction
at C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqdt33\node_modules
\@truffle\hdwallet-provider\node_modules\web3-provider-engine\subproviders\provi
der.js:18:36
at XMLHttpRequest.request.onreadystatechange (C:\Users\Diddi\Documents\mjukv
aruteknik\examensarbete\tqdt33\node_modules\web3-providers-http\src\index.js:96:
13)
at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\Diddi\Documents\mjukvar
uteknik\examensarbete\tqdt33\node_modules\xhr2-cookies\xml-http-request-event-ta
rget.ts:44:13)
at XMLHttpRequest._setReadyState (C:\Users\Diddi\Documents\mjukvaruteknik\ex
amensarbete\tqdt33\node_modules\xhr2-cookies\xml-http-request.ts:219:8)
at XMLHttpRequest._onHttpResponseEnd (C:\Users\Diddi\Documents\mjukvarutekni
k\examensarbete\tqdt33\node_modules\xhr2-cookies\xml-http-request.ts:345:8)
at IncomingMessage.<anonymous> (C:\Users\Diddi\Documents\mjukvaruteknik\exam
ensarbete\tqdt33\node_modules\xhr2-cookies\xml-http-request.ts:311:39)
at IncomingMessage.emit (events.js:228:7)
at endReadableNT (_stream_readable.js:1185:12)
at processTicksAndRejections (internal/process/task_queues.js:81:21)
smart contract function
mapping(uint256 => uint256[]) public submissions;
function addSubmissionNoCheck(uint256 key, uint256 timeAtLocation) external {
submissions[key].push(timeAtLocation);
}
Update:
I have removed the gas limit specification as per my own solution below and instead and overfunded the accounts and it seems to work now. I've ran multiple times doing 20 transactions from 20 different accounts. However i feel like if the problem was insufficent funds in the accounts i should receive the Insufficient funds for gas * price + value
error.
then
clause. I also manually checked some of the addresses supposedly used in my for loop on etherscan but i find no failed transactions according to etherscan, in fact no new transactions at all so they are not being sentaddSubmissionNoCheck
, notaddSubmission
! May I speculate that you have arequire
statement in the former?