# Ethereum eth_sendRawTransaction RPC method

Ethereum API method that creates a new message call transaction. Or contract creation for signed transactions.

Parameters:

  • data — the signed transaction. Typically, signed with a library such as web3.py or web3.js using the sender's private key.

Returns:

  • result — the transaction hash or the zero hash if the transaction is not yet available.

Example:

Information

You can use a testnet. Web3.js requires the ethereumjs-tx (opens new window) package. Install with npm install ethereumjs-tx.

  • web3.js
  • web3.py
  • eth.rb
  • cURL
const Web3 = require("web3");
const node_url = "CHAINSTACK_NODE_URL";
const web3 = new Web3(node_url);
var Tx = require("ethereumjs-tx").Transaction;

// Logic of this code:
    // Set the addresses and private key to sign the transaction
    // Build transaction
    // Sign and send the transaction

// Addresses and private key
const sender = "SENDER_ADDRESS";
const receiver = "RECEIVER_ADDRESS";
const private_key = Buffer.from("PRIVATE_KEY", "hex");

// Build the transaction
web3.eth.getTransactionCount(sender, (err, transactionCount) => {
    const transaction_Object = {
        to: receiver,
        gasPrice: web3.utils.toHex(web3.utils.toWei("20", "gwei")),
        gasLimit: web3.utils.toHex(21000),
        nonce: web3.utils.toHex(transactionCount),
        value: web3.utils.toHex(web3.utils.toWei("0.5", "ether")),
    };

    // Signing the transaction

    // create a new transaction object to sign
    const tx = new Tx(transaction_Object, {
        chain: "ropsten"
    });

    // sign the transaction using the private key  
    tx.sign(private_key);

    //   Send signed transaction to the blockchain
    const sTx = tx.serialize();
    const rawTransaction = "0x" + sTx.toString("hex");

    web3.eth.sendSignedTransaction(rawTransaction, (err, hash) => {
        console.log("TxHash:" + hash);
        //console.log(err);
    });
})

TIP

Since eth_sendRawTransaction is a request used for writing to the blockchain and changing its state, it is not possible to execute the same request again. If you were to copy the cURL example given above, you will not get the expected response.