Description
Transactions represent fundamental operations on blockchain networks. In the context of Ethereum Virtual Machine (EVM)-compatible chains, these operations are initiated through the eth_sendTransaction method. Transactions encompass various actions such as:
- Transferring native tokens (e.g., Ether)
- Sending ERC-20/721 tokens
- Deploying smart contracts
- Modifying blockchain state
All transactions require digital signatures from external accounts or key pairs for authentication. When using OKX Web3 Wallet, developers can initiate transactions through the okxwallet.request interface.
Transaction Parameters
Legacy Transactions
Gas Price [Optional]
- Determines transaction processing priority
- Higher values typically result in faster confirmation
- Default networks often provide preset options ("slow", "medium", "fast")
- Particularly relevant for private blockchains with custom fee structures
Gas Limit [Optional]
- Represents maximum computational units a transaction can consume
- Automatically calculated in most cases
- Manual adjustment may benefit specific smart contract interactions
Recipient Address (to) [Optional]
- Hexadecimal-encoded destination address
- Required for all transactions except contract creation
- Omit when deploying new contracts (include
datainstead)
Value [Optional]
- Amount of native currency to transfer (hexadecimal-encoded)
- Represented in smallest denomination (e.g., Wei for Ether)
- Recommended to use libraries like BN.js for precise value handling
Data [Optional]
- Essential for contract deployment
- Encodes method calls and parameters
- Follows Solidity ABI specifications
Chain ID
- Derived from
okxwallet.networkVersion - Identifies target blockchain network
Return Value
- 32-byte transaction hash
- Zero hash for pending transactions
- Contract addresses available via receipt after mining
EIP-1559 Transactions
Introduced significant fee structure changes:
Max Priority Fee Per Gas [Optional]
- Tip for miners/validators
- Incentivizes transaction prioritization
Max Fee Per Gas [Optional]
- Total maximum fee per gas unit
- Includes base fee and priority components
๐ Learn more about EIP-1559 transaction optimizations
Practical Implementation Example
const transactionParameters = {
nonce: '0x00',
to: '0xRecipientAddress',
value: '0xAmountInWei',
gas: '0xGasLimit',
maxPriorityFeePerGas: '0xPriorityFee',
maxFeePerGas: '0xMaxFee'
};
okxwallet.request({
method: 'eth_sendTransaction',
params: [transactionParameters]
})
.then((txHash) => console.log('Transaction Hash:', txHash))
.catch((error) => console.error('Error:', error));FAQ Section
Q: How do I estimate appropriate gas fees?
A: Most wallets provide automatic fee estimation. For custom needs, use eth_estimateGas RPC call.
Q: What's the difference between legacy and EIP-1559 transactions?
A: EIP-1559 introduces variable base fees and separates miner tips, providing more predictable fee structures.
Q: How long do transactions typically take to confirm?
A: Confirmation times vary by network congestion and fee selection - from seconds to several minutes.
Q: Can I cancel a pending transaction?
A: Yes, by sending a replacement transaction with the same nonce and higher fee.
๐ Explore advanced wallet integration techniques
Q: What happens if my transaction fails?
A: You still pay gas fees for computation attempts. Always check estimated gas and contract interactions.
Q: How do I track transaction status?
A: Use blockchain explorers with your transaction hash or eth_getTransactionReceipt RPC method.