Skip to main content

Send tx

Transactions change the on-chain state and therefore must be confirmed by the user in the wallet before being issued. In UKey Wallet Ethereum Provider, DApp initiates transaction requests through eth_sendTransaction. It can be used for native currency transfers, token contract calls, contract deployment, or other operations that require writing on-chain status.

When using Provider directly to send a transaction, you need to construct the transaction inputs object and then call provider.request:

const transactionParameters = {
nonce: "0x00", // Note: UKey Wallet browser extension ignores this inputs
gasPrice: "0x09184e72a000", // The user can still tweak this in the UKey Wallet browser extension confirmation UI
gas: "0x2710", // The user can still tweak this in the UKey Wallet browser extension confirmation UI
to: "0x0000000000000000000000000000000000000000", // Leave empty only when creating a contract
from: connectedAddress, // This needs to match whichever address the user currently has active
value: "0x00", // Only necessary when the sender is transferring ETH directly to a recipient
data: "0x7f7465737432000000000000000000000000000000000000000000000000000000600057", // Payload for contract deployment or contract calls
chainId: "0x3", // Helps prevent cross-chain replay; the UKey Wallet browser extension will usually populate it for you
};

// Note: txHash is a hexadecimal string
// Like any RPC request, this can still throw
const provider = (window.$ukey && window.$ukey.ethereum) || window.ethereum;
const txHash = await provider.request({
method: "eth_sendTransaction",
requestParams: [transactionParameters],
});

Reference snippet

Transaction field set

The wallet will fill in or re-estimate some inputs, but understanding these fields will help you construct more reliable transaction requests.

Nonce (ignored)

This field is currently ignored by the UKey Wallet browser extension.

Each transaction in the Ethereum account has a nonce, which is used to ensure the order of transactions and prevent repeated execution. The nonce of a valid transaction must match the account's current pending queue.

When users initiate transactions on multiple DApps or devices at the same time, manually specifying the nonce can easily cause conflicts or block subsequent transactions.

Therefore, ask the wallet manage the nonce and transaction queue, and the DApp should not rely on custom nonce to control the transaction sequence.

Gas Price (optional)

This optional field usually only needs to be explicitly passed in by the DApp in private chains or special networks.

Gas price will affect the priority of transactions being packaged. The higher the setting, the faster the transaction may be processed, but the fee paid by the user will also increase.

On common networks, the wallet will help users choose the appropriate fee bracket, and users can also adjust the fee on the confirmation page.

If your DApp is connected to a network where the wallet cannot accurately estimate fees, you can pass in a suggested value, but you should still allow the user to finalize it in the wallet.

Gas Limit (optional)

This field can be omitted. Most DApps can allow wallets or RPCs to estimate automatically.

Only if your contract call really requires a special gas limit, explicitly pass in this field.

To (semi-optional)

to is a hexadecimal encoded Ethereum address. In addition to contract creation, ordinary transfers and contract calls require the recipient address.

If to is not present, but data is provided, the transaction will be treated as a contract creation request.

Value (optional)

value is the hexadecimal encoded native coin amount. The unit on the Ethereum mainnet is wei, which is 1e-18 ETH.

On-chain amounts often exceed the safe integer range of JavaScript Numbers. When constructing amounts, use bigint, BN.js, or the unit conversion tools provided by viem/ethers.

Data (semi-optional)

data is required when creating the contract.

Contract calls also rely on data to represent method selectors and inputs encodings. For the encoding method, please refer to Solidity ABI Specification.

Chain ID (currently ignored)

The current Chain ID will be determined based on the network selected by the user in the wallet. DApps should proactively check the current eth_chainId before making a transaction to avoid sending the transaction to an unexpected network.