Broadcast Transaction (Trezor)

The code example uses ethers.js 6.10.0. To sign and broadcast a transaction to the Ethereum network, follow these steps:

  1. Retrieve the signed transaction transactions in Base64 encrypted format.

  2. Sign and broadcast the transaction using the following code:

    require("dotenv").config();
    const { ethers } = require('ethers');
    
    async function broadcast() {
        console.log("Started");
    
        // Enter the signed raw transaction
        const rawTransaction = process.env.RAW_TRANSACTION;
    
        // Enter the selected RPC URL (e.g. "https://ethereum-goerli.publicnode.com" )
        const rpcURL = process.env.RPC_URL;
    
        // Initialize the provider using the RPC URL
        const provider = new ethers.JsonRpcProvider(rpcURL);
    
        // Send the signed transaction
        const transactionResponse = await provider.broadcastTransaction(rawTransaction);
    
        return transactionResponse;
    }
    
    broadcast()
        .then((transactionResponse) => {
            console.log(
                "Transaction broadcasted, transaction hash:",
                transactionResponse.hash
            );
        })
        .catch((error) => {
            console.error("Error:", error);
        })
        .finally(() => {
            console.log("Finished");
        });
    

What's Next?