Skip to Content
dApp Integration

eth_sendTransaction

Creates a new transaction and prompts the user to confirm it. Returns the transaction hash on success.


Parameters

Array containing a single transaction object:

FieldTypeRequiredDescription
fromstringYesSender address
tostringNoRecipient address (omit for contract creation)
valuestringNoValue to send in wei (hex)
datastringNoContract call data or bytecode
gasstringNoGas limit (hex)
gasPricestringNoGas price in wei (hex), for legacy transactions
maxFeePerGasstringNoMax fee per gas (hex), for EIP-1559
maxPriorityFeePerGasstringNoMax priority fee (hex), for EIP-1559
noncestringNoTransaction nonce (hex)

Returns

string - The transaction hash (32-byte hex string)


Examples

Send ETH

const txHash = await window.$onekey.ethereum.request({ method: 'eth_sendTransaction', params: [{ from: '0xYourAddress...', to: '0xRecipientAddress...', value: '0xDE0B6B3A7640000', // 1 ETH in wei }] }) console.log('Transaction hash:', txHash)

Call Contract Function

const txHash = await window.$onekey.ethereum.request({ method: 'eth_sendTransaction', params: [{ from: '0xYourAddress...', to: '0xContractAddress...', data: '0xa9059cbb...', // Encoded function call gas: '0x5208', }] })

EIP-1559 Transaction

const txHash = await window.$onekey.ethereum.request({ method: 'eth_sendTransaction', params: [{ from: '0xYourAddress...', to: '0xRecipientAddress...', value: '0xDE0B6B3A7640000', maxFeePerGas: '0x2540BE400', // 10 Gwei maxPriorityFeePerGas: '0x3B9ACA00', // 1 Gwei }] })

Errors

CodeMessageDescription
4001User rejected the requestUser denied the transaction
-32000Insufficient fundsNot enough balance
-32602Invalid paramsInvalid transaction parameters

Notes

  • Always use hex strings with 0x prefix for numeric values
  • If gas is not provided, the wallet will estimate it
  • For EIP-1559 chains, prefer maxFeePerGas over gasPrice
  • The from address must be an account the user has connected
Last updated on