Skip to main content

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:

FieldVariantNeedRemarks
fromstringyesAuthorized sender address
tostringnoRecipient address; leave empty for contract deployment
valuestringnoTransfer amount in wei, encoded as hex
datastringnoCall payload or deployment bytecode
gasstringnoGas limit encoded as hex
gasPricestringnoLegacy gas price
maxFeePerGasstringnoEIP-1559 max fee cap
maxPriorityFeePerGasstringnoEIP-1559 priority fee cap
noncestringnoTransaction 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

CodeMessageDetails
4001User rejected the requestTransaction approval was rejected by the user
-32000Insufficient fundsInsufficient balance
-32602Parameters failed validationTransaction inputs are invalid

illustrate

  • All numeric fields should be hex strings starting with 0x.
  • If gas is not provided, the wallet will attempt to estimate it automatically.
  • For networks that support EIP-1559, use maxFeePerGas and maxPriorityFeePerGas.
  • from must 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.