eth_sendTransaction
Requests the wallet to create and send a transaction. After the user confirms in UKey Wallet, the Provider will broadcast the transaction to the current network and return the transaction hash.
Inputs
Pass an array whose first item is the transaction object:
| Field | Variant | Need | Remarks |
|---|---|---|---|
from | string | yes | Authorized sender address |
to | string | no | Recipient address; leave empty for contract deployment |
value | string | no | Transfer amount in wei, encoded as hex |
data | string | no | Call payload or deployment bytecode |
gas | string | no | Gas limit encoded as hex |
gasPrice | string | no | Legacy gas price |
maxFeePerGas | string | no | EIP-1559 max fee cap |
maxPriorityFeePerGas | string | no | EIP-1559 priority fee cap |
nonce | string | no | Transaction nonce; usually let the wallet fill this |
return value
string - Transaction hash, 32-byte hex string.
Demo
Send ETH
const txHash = await window.$ukey.ethereum.request({
method: "eth_sendTransaction",
requestParams: [
{
from: "0x1a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d",
to: "0x4b6d8f0123456789abcdef0123456789abcdef01",
value: "0x2386f26fc10000", // sample ETH amount, in wei
},
],
});
console.log("Tx hash:", txHash);
Call contract method
const txHash = await window.$ukey.ethereum.request({
method: "eth_sendTransaction",
requestParams: [
{
from: "0x1a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d",
to: "0x2b4d6f8091a3c5e7f9b1d3f507192b4d6f8091a3",
data: "0xa9059cbb...", // Note: Encoded function call
gas: "0x5208",
},
],
});
EIP-1559 Transaction
const txHash = await window.$ukey.ethereum.request({
method: "eth_sendTransaction",
requestParams: [
{
from: "0x1a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d",
to: "0xc4d2e1f0a9876543210fedcba9876543210abcde",
value: "0x2386f26fc10000",
maxFeePerGas: "0x1dcd65000", // fee cap example
maxPriorityFeePerGas: "0x77359400", // priority fee example
},
],
});
error code
| Code | Message | Details |
|---|---|---|
| 4001 | User rejected the request | Transaction approval was rejected by the user |
| -32000 | Insufficient funds | Insufficient balance |
| -32602 | Parameters failed validation | Transaction inputs are invalid |
illustrate
- All numeric fields should be hex strings starting with
0x. - If
gasis not provided, the wallet will attempt to estimate it automatically. - For networks that support EIP-1559, use
maxFeePerGasandmaxPriorityFeePerGas. frommust be a currently authorized account, otherwise the request will fail.- After the transaction is broadcast and still needs to wait for on-chain confirmation, please use RPC or a block explorer to track the hash status.