I've been following a tutorial at . The twist is that I'm attempting to send ETH to the 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',
value: 100,
gas: 30000,
maxFeePerGas: 1000000108,
nonce: nonce,
};
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 running the code, I encounter 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 : replacing maxFeePerGas
with maxPriorityFeePerGas
resolves the issue.
What fundamental concept am I overlooking here?