const {Web3} = require("web3");
require("dotenv").config();
const sPrivateKey = process.env.SENDER_PRIVATE_KEY;
const sPublicKey = process.env.SENDER_PUBLIC_KEY;
const rPublicKey = process.env.RECEIVER_PUBLIC_KEY_KEY;
async function main() {
const web3 = new Web3(
new Web3.providers.HttpProvider(process.env.SEPOLIA_API_KEY)
);
const signer = web3.eth.accounts.privateKeyToAccount(sPrivateKey);
web3.eth.wallet.add(signer);
const estimatedGas = await web3.eth.estimateGas({
from: sPublicKey,
to: rPublicKey,
value: web3.utils.toWei("0.01", "ether"),
});
const tx = {
from: sPublicKey,
to: rPublicKey,
value: web3.utils.toWei("0.01", "ether"),
gas: estimatedGas,
maxPriorityFeePerGas: web3.utils.toWei("3", "gwei"),
maxFeePerGas: web3.utils.toWei("3", "gwei"),
};
const signedTx = web3.eth.signTransaction(tx, signer.privateKey);
console.log(signedTx.rawTransaction);
const receipt = web3.eth.sendSignedTransaction(signedTx.rawTransaction);
console.log(receipt.blockNumber);
}
main().catch((error) => console.log(error));
-
1You did not write where exactly you are getting this error. I can assume that it is sPrivateKey. Is it right?– Alexey SmirnovNov 15 at 5:17
-
Fixed it thanks anyway– seojunchianNov 15 at 11:29
1 Answer
Find the problem and fixed it.
The part I fixed: Instead of rawTransaction after you write signedTx and put dot it shows you raw but I saw in an example of people doing it they wrote rawTransaction so I did the same but didn't work instead of tried raw and worked.
-
Welcome to the Ethereum Stack Exchange! Suggest you write down the problem and fix, so that it can help others?– eth ♦Nov 15 at 15:43