eth_sendRawTransactionare both Ethereum API functions which broadcast a transaction to the Ethereum network so it will be added to a future block. They differ in how they handle signing of the transactions.
eth_sendTransactionis used for sending unsigned transactions, which means the node you are sending to must manage your private key so it can sign the transaction before broadcasting it to the chain. Since Alchemy doesn't hold user's private keys, we do not support this method.
.env, nothing more) in your project directory and add the following (replacing
your-private-key, keeping both within the quotation marks):
sendTx.jsfile, which is where we will configure and send our example transaction, and add the following lines of code to it:
transaction: The transaction object has a few aspects we need to specify
value: This is the amount we wish to send, specified in wei where 10^18 wei = 1 ETH
gas: There are many ways to determine the right amount of gas to include with your transaction. Alchemy even has a gas price webhook to notify you when the gas price falls within a certain threshold. For mainnet transactions, it's good practice to check a gas estimator like Eth Gas Station to determine the right amount of gas to include. 21000 is the minimum amount of gas an operation on Ethereum will use, so to ensure our transaction will be executed we put 30000 here.
maxFeePerGas: This is the amount you are willing to pay per gas for the transaction to execute. Since EIP 1559, this field or the
maxPriorityFeePerGasfield is required.
nonce: see above nonce definition. Nonce starts counting from zero.
data: Used for sending additional information with your transfer, or calling a smart contract, not required for balance transfers, check out the note below.
signedTx: To sign our transaction object we will use the
signTransactionmethod with our
sendSignedTransaction: Once we have a signed transaction, we can send it off to be included in a subsequent block by using