API Reference

eth_sendRawTransaction - Xlayer

Xlayer API - Creates a new message call transaction or a contract creation for signed transactions.

Parameters

  • DATA, The signed transaction data.
params: ["0x<signed-raw-tx-generated-for-chainId-0xc4>"];

Returns

DATA, 32 Bytes - The transaction hash, or the zero hash if the transaction is not yet available.

Use eth_getTransactionReceipt to get the contract address after the transaction was mined when you created a contract.


Example

How to Generate a signed raw transaction (for safety)

// Example with ethers.js v6
import { ethers } from "ethers";

const RPC = "https://xlayer-mainnet.unifra.io/v1/your-api-key";
const provider = new ethers.JsonRpcProvider(RPC);

// Use a funded private key (DO NOT share in code or commits)
const PRIVATE_KEY = process.env.PRIV_KEY;
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);

const main = async () => {
const nonce = await provider.getTransactionCount(wallet.address);
const gasPrice = await provider.getGasPrice();

const tx = {
to: wallet.address, // send to yourself (example)
value: 0n,
nonce,
gasPrice,
gasLimit: 21000n,
chainId: 196 // Xlayer mainnet chainId = 0xc4
};

const rawTx = await wallet.signTransaction(tx);
console.log("RAW_TX:", rawTx);

// Send if desired:
// const sent = await provider.sendTransaction(rawTx);
// console.log("TX_HASH:", sent.hash);
};

main();

Request

curl https://xlayer-mainnet.unifra.io/v1/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["0x<signed-raw-tx-generated-for-chainId-0xc4>"],"id":1}'
URL: https://xlayer-mainnet.unifra.io/v1/your-api-key
RequestType: POST
Body:
{
  "jsonrpc":"2.0",
  "method":"eth_sendRawTransaction",
  "params":["0x<signed-raw-tx-generated-for-chainId-0xc4>"],
  "id":1
}

Result

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
}
Language
Click Try It! to start a request and see the response here!