I am following this tutorial -> https://docs.alchemy.com/alchemy/tutorials/sending-txs The only difference is that i am trying to eth to ropsten test faucet
async function main() {
require('dotenv').config();
const { API_URL, PRIVATE_KEY } = process.env;
const { createAlchemyWeb3 } = require('@alch/alchemy-web3');
const web3 = createAlchemyWeb3(API_URL);
const myAddress = 'xxxx'; //TODO: replace this address with your own public address
const nonce = await web3.eth.getTransactionCount(myAddress, 'latest'); // nonce starts counting from 0
console.log(nonce);
const transaction = {
to: '0x9f1099b301716892d17d576387027cE5B73E2c20', // faucet address to return eth
value: 100,
gas: 30000,
maxFeePerGas: 1000000108,
nonce: nonce,
// optional data field to send message or execute smart contract
};
const signedTx = await web3.eth.accounts.signTransaction(
transaction,
PRIVATE_KEY
);
web3.eth.sendSignedTransaction(
signedTx.rawTransaction,
function (error, hash) {
if (!error) {
console.log(
'🎉 The hash of your transaction is: ',
hash,
"\n Check Alchemy's Mempool to view the status of your transaction!"
);
} else {
console.log(
'❗Something went wrong while submitting your transaction:',
error
);
}
}
);
}
main();
When i am running code i am getting this error -> Error: maxFeePerGas cannot be less than maxPriorityFeePerGas (The total must be the larger of the two) (tx type=2 hash=not available (unsigned) nonce=23 value=100 signed=false hf=london maxFeePerGas=1000000108 maxPriorityFeePerGas=2500000000)
Update : if i replace maxFeePerGas
with maxPriorityFeePerGas
this works
What am i missing conceptually?
It seems that the default value of maxPriorityFeePerGas
was changed from 1.0 gwei
to 2.5 gwei
due to some incentive mechanism for miners.
Follow this issue for more detailed information.
Hence, if we don't set the maxPriorityFeePerGas
parameter, the default value 2.5 gwei
would larger than maxFeePerGas
, which is 1.0 gwei
we set and violate the rule.
We can solve this issue by either setting maxPriorityFeePerGas
smaller than 1.0 gwei
or changing maxFeePerGas
larger than 2.5 gwei
.