evm_encode_contract_data
Encodes function calls into hex transaction data for raw transaction construction, batch operations, or multi-sig proposals.
Instructions
Encode function call into transaction input data for raw transaction construction.
Converts function name and parameters into hex-encoded transaction data. Used for building raw transactions, batch operations, multi-sig proposals, or when you need transaction data before signing.
CRITICAL RULES:
Requires correct ABI for function being encoded
Parameters must match function signature exactly
Output is hex-encoded transaction input data
Can be used in raw transactions or eth_sendRawTransaction
Function selector automatically prepended to encoded parameters
PARAMETERS:
chain: EVM chain context (required)
Used for context, doesn't affect encoding
Helps identify target chain
abi: Contract ABI (required)
Must include function being encoded
Function signature used for selector computation
Parameter types define encoding rules
Get from block explorer or project docs
functionName: Name of function to encode (required)
Exact name as in contract
Case-sensitive
Examples: "transfer", "approve", "swapExactTokensForTokens"
params: Function parameters array (optional)
Must match function signature order and types
Correct types critical for proper encoding
Empty array [] if no parameters
Examples: ["0x742d35...", "1000"], []
EXAMPLES: ✅ Encode ERC20 transfer: {chain: "polygon", abi: [...ERC20_ABI], functionName: "transfer", params: ["0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb", "1000000000000000000"]}
✅ Encode token approval: {chain: "arbitrum", abi: [...], functionName: "approve", params: ["0xSpender...", "115792089237316195423570985008687907853269984665640564039457584007913129639935"]}
✅ Encode function with no parameters: {chain: "ethereum", abi: [...], functionName: "totalSupply", params: []}
❌ Invalid - wrong parameter types: {params: [1000, "0xAddress"]} // Numbers should be strings
❌ Invalid - parameter count mismatch: {functionName: "transfer", params: ["0xAddress"]} // Missing amount parameter
SUPPORTED EVM CHAINS (7 networks): • ethereum (Sepolia) - EIP-1559 enabled, ~12s blocks, moderate gas costs • polygon (Amoy) - Low fees, fast finality (~2s), layer 2 • avalanche (Fuji C-Chain) - Sub-second finality, dynamic fees • bsc (BNB Testnet) - 3s blocks, low gas costs, Binance ecosystem • arbitrum (Sepolia) - Optimistic rollup, low fees, Ethereum security • base (Sepolia) - Coinbase layer 2, EIP-1559, low fees • worldchain (World Sepolia) - World Network testnet, EIP-1559
CRITICAL GAS CONSIDERATIONS:
Ethereum: High gas costs, use gas oracle for timing
Polygon/BSC: Very low gas, safe for frequent transactions
Arbitrum/Base: L2 optimizations, ~10-50x cheaper than Ethereum
Avalanche: Dynamic fees, can spike during congestion
Always check gas price before executing transactions
TESTNET TOKENS: All chains use testnet tokens with NO REAL VALUE. Faucets available for all supported networks.
OUTPUT STRUCTURE: • success: Boolean indicating encoding success • chain: Chain context • functionName: Function being encoded • functionSignature: Full function signature • encodedData: Hex-encoded transaction data (0x...) • methodId: Function selector (first 4 bytes) • parameters: Original parameters provided • executionTime: Time taken in milliseconds
COMMON MISTAKES:
Wrong parameter types (number instead of string)
Incorrect parameter order
Missing required parameters
Using wrong ABI
Not converting values to proper units
USE CASES:
Build raw transactions manually
Prepare multi-sig transaction proposals
Batch multiple contract calls
Create transaction data for wallets
Simulate transactions before signing
ENCODING PROCESS:
Compute function selector from signature
Encode each parameter by type
Concatenate selector + encoded params
Return hex string with 0x prefix
FUNCTION SELECTOR: First 4 bytes of encoded data:
Keccak256 hash of function signature
Example: transfer(address,uint256)
Always 8 hex characters (4 bytes)
Uniquely identifies function
PARAMETER ENCODING: Types encoded differently:
address: 20 bytes, left-padded to 32 bytes
uint256: 32 bytes, big-endian
string: Length-prefixed, hex-encoded
bytes: Length-prefixed, raw bytes
arrays: Length + elements
bool: 0x00 (false) or 0x01 (true)
USING ENCODED DATA:
Build raw transaction object
Set 'data' field to encoded output
Set 'to' field to contract address
Sign transaction with private key
Broadcast with eth_sendRawTransaction
RAW TRANSACTION EXAMPLE: { to: "0xContractAddress", data: "0xa9059cbb000000000000000000000000...", // From this tool gasLimit: "100000", gasPrice: "20000000000", nonce: 42, chainId: 137 }
MULTI-SIG PROPOSALS:
Encode function call (this tool)
Create proposal with encoded data
Collect signatures from signers
Execute multi-sig transaction
BATCH OPERATIONS: Encode multiple calls:
Encode each function call separately
Combine encoded data in batch contract
Execute all in single transaction
COMPLEX PARAMETERS: Encoding arrays and tuples:
address[]: Multiple addresses
(uint256,string): Structured data
Nested types: Recursive encoding
VERIFICATION: After encoding:
Decode with evm_decode_contract_data
Verify function and parameters correct
Double-check before signing
SECURITY NOTES:
Verify parameters before encoding
Check function name is correct
Test with small amounts first
Understand what function does
Use on testnet before mainnet
Running on Linux.
LINUX-SPECIFIC NOTES:
Package manager: apt (Ubuntu/Debian), yum (RHEL/CentOS), or pacman (Arch)
Python 3 is typically 'python3' command
GNU tools are standard
Use 'xdg-open' command to open files/applications
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"chain": "<chain>",
"abi": "<abi>",
"functionName": "<functionName>"
},
"name": "evm_encode_contract_data"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| abi | Yes | Contract ABI (JSON array) | |
| chain | Yes | EVM chain context | |
| params | No | Function parameters (optional) | |
| functionName | Yes | Function name to encode |