Skip to Content
dApps
On this page

Sending Transactions

Use eth_sendTransaction to request a transaction from a connected account. The wallet asks the user to review and approve it. A successful request returns a transaction hash; it does not mean the transaction has been confirmed or executed successfully.

Example

const provider = window.$onekey?.ethereum; if (!provider) throw new Error('OneKey Ethereum provider is unavailable.'); const [from] = await provider.request({ method: 'eth_requestAccounts' }); const chainId = await provider.request({ method: 'eth_chainId' }); // Check chainId against your application's intended network before continuing. const to = '<RECIPIENT_EVM_ADDRESS>'; // Replace with a valid address. try { const txHash = await provider.request({ method: 'eth_sendTransaction', params: [{ from, to, value: '0x0', }], }); console.log('Submitted transaction:', txHash); } catch (error) { console.error(error.code, error.message); }

Call this flow from a user action. Replace the recipient and value before sending. Query eth_getTransactionReceipt on the same chain to determine inclusion and execution status; a pending transaction has no receipt yet.

Transaction Parameters

ParameterMeaning
fromConnected account authorized to send the transaction
toRecipient address; omit only for contract creation
valueNative-currency amount as a hexadecimal quantity, in the smallest unit (wei on Ethereum)
dataHex-encoded contract call data or contract creation bytecode
gasOptional gas limit; this is a quantity of gas, not a gas price
gasPriceOptional fee per unit of gas for a legacy transaction
maxFeePerGas, maxPriorityFeePerGasFee fields for an EIP-1559 transaction; do not combine these with gasPrice
nonceAccount transaction sequence number; normally let the wallet manage it

Use integer-safe arithmetic for amounts; avoid floating-point calculations when converting to wei. Let the wallet estimate fees unless your application has a specific reason to supply them. The user may review or adjust transaction details in the wallet.

Network and Account Changes

Read eth_chainId before preparing a transaction and handle chainChanged and accountsChanged as described in Provider API. Rebuild account- or network-dependent transaction data after a change.

Demo

Open example 

Last updated on