Is ethers broadcastTransaction same as web3js sendSignedTransaction method ? Does it emit events ? If yes, how ? #4921
Unanswered
gauravmindzk
asked this question in
Q&A
Replies: 1 comment
-
@ricmoo gm ser :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone,
Since web3js is getting sunset soon ( #4921 (comment) ) , I'm working on migrating my server code from web3js ( v1 ) to ethers ( v6 ) .
First Question
Is ethers's broadcastTransaction method similar to web3js's sendSignedTransaction method ?
Second Question
Now, In my web3js code , first a txn is signed , then the signed txn is broadcasted . I'll share my web3js code snippet and ethers code that I've setup so far.
` const provider = new Web3.providers.HttpProvider('polygon-mumbai-infura-url');
const web3 = new Web3(provider);
`
`
const signAndSendSignedTxn = async () => {
// Create a new wallet instance
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);
const etherVal = ethers.parseEther("0.0001");
// Retrieve the chainId from the provider
const network = await provider.getNetwork();
const chainId = network.chainId;
const transactionCount = await provider.getTransactionCount(ADDR, "pending");
console.log("transaction count :",transactionCount);
console.log("etherVal :",etherVal);
const feeData = await provider.getFeeData();
console.log("feeData :",feeData);
const txn = {
from: ADDR,
to: "0xreceiveraddress",
value: etherVal, // Specify the amount of ETH to send
chainId: chainId,
nonce: transactionCount,
gasLimit:21000,
maxFeePerGas: feeData.maxFeePerGas,
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas
}
// Sign the transaction
const signedTxn = await wallet.signTransaction(txn)
console.log("signedTxn :",signedTxn);
const receipt = await provider.broadcastTransaction(signedTxn);
console.log("receipt logged :",receipt);
}
signAndSendSignedTxn()
`
you can see that my ethers code doesn't have event emitted setup like my web3js code , how can I setup my ethers code similar to my web3js code
Beta Was this translation helpful? Give feedback.
All reactions