I have been trying to send a transaction on the Ethereum testnet Rinkeby for the past few days and keep getting this error no matter how much I increase the gas to.
"Unhandled rejection Error: Returned error: intrinsic gas too low"
The data I am sending is:
"0x7b22416e7377657273223a5b7b225175657374696f6e223a2231222c22416e73776572223a2234227d2c7b225175657374696f6e223a2232222c22416e73776572223a2234227d2c7b225175657374696f6e223a2233222c22416e73776572223a2234227d2c7b225175657374696f6e223a2234222c22416e73776572223a2234227d2c7b225175657374696f6e223a2235222c22416e73776572223a2234227d2c7b225175657374696f6e223a2236222c22416e73776572223a2234227d5d7d"
after it has been converted to a Hex.
I have added my code below.
var number = web3.eth.getTransactionCount(address).then(function(count) {
console.log("Count " + count);
var privateKey = new EthJS.Buffer.Buffer(privateKey, 'hex');
console.log(web3.utils.toHex(finalAnswers));
var rawTx = {
nonce: web3.utils.toHex(count),
to: '0xF1aA87F7058e5ABE561cCe8A466eE1CC17d69639',
value: 0,
data: web3.utils.toHex(finalAnswers),
gas: 50000,
gasPrice: web3.utils.toWei('300', 'gwei')
};
var tx = new EthJS.Tx(rawTx);
tx.sign(privateKey);
var serializedTx = tx.serialize();
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex')).on('receipt', console.log);
});
I have been trying to send a transaction on the Ethereum testnet Rinkeby for the past few days and keep getting this error no matter how much I increase the gas to.
"Unhandled rejection Error: Returned error: intrinsic gas too low"
The data I am sending is:
"0x7b22416e7377657273223a5b7b225175657374696f6e223a2231222c22416e73776572223a2234227d2c7b225175657374696f6e223a2232222c22416e73776572223a2234227d2c7b225175657374696f6e223a2233222c22416e73776572223a2234227d2c7b225175657374696f6e223a2234222c22416e73776572223a2234227d2c7b225175657374696f6e223a2235222c22416e73776572223a2234227d2c7b225175657374696f6e223a2236222c22416e73776572223a2234227d5d7d"
after it has been converted to a Hex.
I have added my code below.
var number = web3.eth.getTransactionCount(address).then(function(count) {
console.log("Count " + count);
var privateKey = new EthJS.Buffer.Buffer(privateKey, 'hex');
console.log(web3.utils.toHex(finalAnswers));
var rawTx = {
nonce: web3.utils.toHex(count),
to: '0xF1aA87F7058e5ABE561cCe8A466eE1CC17d69639',
value: 0,
data: web3.utils.toHex(finalAnswers),
gas: 50000,
gasPrice: web3.utils.toWei('300', 'gwei')
};
var tx = new EthJS.Tx(rawTx);
tx.sign(privateKey);
var serializedTx = tx.serialize();
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex')).on('receipt', console.log);
});
Share
Improve this question
edited Mar 31, 2023 at 18:46
TylerH
21.1k79 gold badges79 silver badges114 bronze badges
asked Jun 15, 2018 at 6:23
Chad BlanchardChad Blanchard
611 gold badge1 silver badge2 bronze badges
3
-
Change
gas: 50000
togasLimit: 50000
. You may have to increase the value as well (50k may not be enough). – Adam Kipnis Commented Jun 15, 2018 at 7:57 - Thank You for your reply! i got a different error " Returned error: insufficient funds for gas * price + value" which i dont understand as i have 18 eth in the account and keep getting the error when i set the limits to gasLimit: 10000, gasPrice: web3.utils.toWei('2', 'gwei') – Chad Blanchard Commented Jun 15, 2018 at 8:26
- Explicitly include the “from” parameter in your transaction object. If that doesn’t solve it, confirm your balance by adding a debug call to web3.eth.getBalance(). You may be connecting to a different network than you’re expecting. – Adam Kipnis Commented Jun 15, 2018 at 13:09
2 Answers
Reset to default 2The reason why you're getting this error is because gasPrice
is higher than gasLimit
. You need to allocate more gas by setting a higher gasLimit
.
And as @AdamKipris suggested in the ments, you should use gasLimit:
instead of gas:
when building your transaction.
In my case, some of the methods has to bet set Gas Limit manually so I switch to a default gas limit for transaction. In pancakeswap reference, it is 20,000 units https://github./pancakeswap/pancake-frontend/blob/master/src/config/index.ts#L31
You might adapt the prop to gas
though
And the code look like this:
const txReceipt = await callWithGasPrice(
wethContract,
"deposit",
undefined,
{
value: `0x${inputAmount.raw.toString(16)}`,
gasPrice,
gasLimit: DEFAULT_GAS_LIMIT,
}
);