Skip to main content
Glama

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:

  1. Compute function selector from signature

  2. Encode each parameter by type

  3. Concatenate selector + encoded params

  4. 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:

  1. Build raw transaction object

  2. Set 'data' field to encoded output

  3. Set 'to' field to contract address

  4. Sign transaction with private key

  5. 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:

  1. Encode function call (this tool)

  2. Create proposal with encoded data

  3. Collect signatures from signers

  4. Execute multi-sig transaction

BATCH OPERATIONS: Encode multiple calls:

  1. Encode each function call separately

  2. Combine encoded data in batch contract

  3. 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:

  1. Decode with evm_decode_contract_data

  2. Verify function and parameters correct

  3. 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

NameRequiredDescriptionDefault
abiYesContract ABI (JSON array)
chainYesEVM chain context
paramsNoFunction parameters (optional)
functionNameYesFunction name to encode

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A3.6/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden and does so well: it documents the four-step encoding process, selector computation, per-type parameter encoding, the full output field list, and security notes. This is substantive behavioral disclosure rather than restated schema, though it is padded with irrelevant material (gas costs, faucets, Linux package managers).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The key information is front-loaded, but the body sprawls across chain-by-chain gas commentary, testnet token notes, and a trailing 'LINUX-SPECIFIC NOTES' block that has nothing to do with ABI encoding. Much of the middle content (raw transaction templates, parameter encoding theory) belongs in docs, not a tool definition.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For an encoding tool with no output schema, the description covers inputs, outputs, encoding mechanics, verification path, and common failure modes — an agent has enough to call it correctly. The one material gap is the unresolved overlap with evm_encode_function_data.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the baseline is 3. The description does add real meaning beyond the schema — notably that chain is context-only and does not affect encoding, that functionName is case-sensitive and exact, and that params must match signature order with string-typed numbers — but it does not fully compensate for anything since the schema already documents all four.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The opening line states a specific verb and resource — 'Encode function call into transaction input data for raw transaction construction' — and the OUTPUT STRUCTURE section confirms what is produced. It does not, however, differentiate itself from the near-identical sibling evm_encode_function_data, leaving the agent to guess which encoder to pick.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The USE CASES list (raw transactions, multi-sig proposals, batch calls, wallet data, pre-signing simulation) and the VERIFICATION step pointing at evm_decode_contract_data give clear positive guidance. There are no explicit when-not-to-use conditions and no routing away from the duplicate encoder sibling.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools