eth_sendRawTransaction
将离线签名好的交易广播到网络。你需要先在本地完成签名。
DATA— 已签名交易数据(十六进制编码)。
DATA(32 字节)— 交易哈希;若交易暂不可用,也可能返回零哈希。
curl -X POST https://eth-mainnet.blockreq.com/v1/rpc/YOUR_API_KEY \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "method": "eth_sendRawTransaction", "params": ["0xf86c808504a817c80082520894..."], "id": 1 }'⚠️ 该方法必须使用私有端点(API Key),公开端点不可用。
{ "jsonrpc": "2.0", "id": 1, "result": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"}JavaScript (ethers.js v6)
Section titled “JavaScript (ethers.js v6)”import { JsonRpcProvider, Wallet } from "ethers";const provider = new JsonRpcProvider("https://eth-mainnet.blockreq.com/v1/rpc/YOUR_API_KEY");const wallet = new Wallet("0xYOUR_PRIVATE_KEY", provider);
const tx = await wallet.sendTransaction({ to: "0xRecipientAddress", value: "1000000000000000000", // 1 ETH (wei)});console.log("Tx hash:", tx.hash);await tx.wait();console.log("Confirmed!");Python (web3.py)
Section titled “Python (web3.py)”from web3 import Web3w3 = Web3(Web3.HTTPProvider("https://eth-mainnet.blockreq.com/v1/rpc/YOUR_API_KEY"))
signed = w3.eth.account.sign_transaction({ "to": "0xRecipientAddress", "value": w3.to_wei(1, "ether"), "gas": 21000, "gasPrice": w3.eth.gas_price, "nonce": w3.eth.get_transaction_count("0xYourAddress"), "chainId": 1}, "0xYOUR_PRIVATE_KEY")
tx_hash = w3.eth.send_raw_transaction(signed.raw_transaction)print(f"Tx hash: {tx_hash.hex()}")| Method | Cost |
|---|---|
| eth_sendRawTransaction | 20 RU |