Best Practices
Overview
Following best practices when working with EVM transactions on Sei ensures secure and reliable interactions. This guide covers essential security protocols, transaction analysis techniques, and error handling patterns to help you avoid common pitfalls and build robust applications.
Transaction Analysis
When analyzing transactions, follow these essential practices:
- Always verify EVM transactions thoroughly
- Use
cast
to decode input data when working with EVM transactions - Keep track of gas parameters
- Monitor transaction status on the EVM layer
Analysis Tips:
# Use Foundry's cast tool for detailed transaction inspection
cast tx 0x5010e6600e67f04a9bc3d3b670a7c2de380b180713d9a014a5dbd76b7e2190f1 \
--rpc-url=http://url-to-sei-cosmos-rpc
# Get transaction receipt to verify success
cast receipt 0x5010e6600e67f04a9bc3d3b670a7c2de380b180713d9a014a5dbd76b7e2190f1 \
--rpc-url=http://url-to-sei-cosmos-rpc
# Decode transaction input data
cast 4byte-decode 0xa9059cbb000000...
Transaction Analysis Checklist: Always verify transaction success before proceeding. Check gas usage to optimize future transactions. Use Foundry’s cast tool for detailed transaction inspection.
Error Handling
Handle potential EVM transaction issues with proper monitoring:
try {
// Check EVM transaction status
const evmStatus = await checkEvmStatus(txHash);
if (!evmStatus.success) {
const evmError = await cast.call(['tx', txHash, '--rpc-url', evmRpcUrl]);
console.error('EVM transaction failed:', evmError);
}
} catch (error) {
console.error('Transaction analysis failed:', error);
}
Best Practices for Error Handling:
- Always check transaction status on both Cosmos and EVM layers
- Use detailed error logging for debugging failed transactions
- Implement retry logic for network-related failures
- Monitor gas usage and adjust limits accordingly
Security Guidelines
Critical Security Requirements: Keep private keys secure and never include them in templates. Use an .env
file or other environment variables when working with wallet keys or mnemonics. Never commit sensitive information to version control. Always verify transaction details before signing.
Environment Variable Setup:
# Create .env file for sensitive data
WALLET_NAME=mykey
EVM_RPC_URL=http://url-to-sei-evm-rpc
PRIVATE_KEY=your_private_key_here
# Add .env to .gitignore
echo ".env" >> .gitignore
Secure Transaction Execution:
# Use environment variables in commands
seid tx evm send 0x1234567890abcdef... 1000000000000000000 \
--from=$WALLET_NAME \
--evm-rpc=$EVM_RPC_URL
# Generate transaction template first to verify details
seid tx evm send 0x1234567890abcdef... 1000000000000000000 \
--from=$WALLET_NAME \
--evm-rpc=$EVM_RPC_URL \
--generate-only