Sending a Transaction

Once a web application is connected to Broearn Wallet, it can prompt the user for permission to send transactions on their behalf.

To send a transaction, you will need to have a valid transaction object. It should look a little like this:

{
  from: "0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5",
  to: "0xb233696514F192Da7F0f0Fb1332f18c68cfB6c23",
  gasLimit: "21000",
  maxFeePerGas: "300",
  maxPriorityFeePerGas: "10",
  nonce: "0",
  value: "10000000000"
}

However, this transaction object needs to be signed using the sender's private key. This ensures that only the person that holds the private key can send transactions from the public address.

To prompt Broearn Wallet to send a transaction to the network, refer to the following code snippet

const result = await provider.request({
        method: 'eth_sendTransaction',
        params: [
          {
            from: accounts[0],
            to: '0xb233696514F192Da7F0f0Fb1332f18c68cfB6c23',
            value: '0x0',
            gasLimit: '0x5028',
            gasPrice: '0x2540be400',
            type: '0x0',
          },
        ],
});

This is the building blocks of what you will need to send a transaction. However, if you were to copy/paste this, it would likely fail. There are several pieces of a transaction that are best provided in a dynamic manner. Take a look at our sendTransaction function in our sandbox for reference.

Last updated