Would you please give me advice on what is a method to broadcast my signed TX into the network? Can find any %send% method for provider instance
Here is my code snippet:
export async function signAndBroadcast(address, rawTransaction, jrpcUrl, key) {
const provider = new ethers.JsonRpcProvider(jrpcUrl)
expect( await checkBalance(address, provider)).toBe(true)
// Initialize a new Wallet instance
const wallet = new ethers.Wallet(key, provider);
// Parse the raw transaction
const tx = ethers.Transaction.from(rawTransaction);
tx.nonce = await provider.getTransactionCount(wallet.address)
const { name, chainId } = await provider.getNetwork()
tx.chainId = chainId
tx.value = ethers.parseUnits('32', 'ether')
tx.gasLimit = 1000000
tx.gasPrice = undefined
tx.type = 2
// Sign the transaction
const signedTransaction = await wallet.signTransaction(tx);
console.log("TX signed: " + signedTransaction)
// Send the signed transaction
const transactionResponse = await provider.sendTransaction(signedTransaction) // no function sendTransaction
transactionResponse
.then((transactionResponse) => {
console.log('Transaction broadcasted, transaction hash:', transactionResponse.hash);
})
.catch((error) => {
console.error('Error:', error);
}).finally(() => {
console.log('Finished')
});
}
Thank you in advance!