Skip to main content
The TypeScript SDK provides utility functions for encoding intents, managing routes, and type conversions when interacting with the Eco Routes Protocol.

Intent Utilities

Types

Call

Represents a contract call to be executed.

TokenAmount

Represents an ERC20 token and amount.

Route

Defines the execution route on the destination chain.

Reward

Defines the reward for intent fulfillment.

Intent

Complete intent structure combining route and reward.

Encoding Functions

encodeRoute

Encodes a route object into ABI-encoded bytes.
Parameters:
  • route: Route object to encode
Returns: ABI-encoded route data as hex string Example:

encodeReward

Encodes a reward object into ABI-encoded bytes.
Parameters:
  • reward: Reward object to encode
Returns: ABI-encoded reward data as hex string Example:

encodeIntent

Encodes a complete intent into ABI-encoded bytes.
Parameters:
  • intent: Complete intent object to encode
Returns: ABI-encoded intent data as hex string Example:

Hashing Functions

hashIntent

Generates cryptographic hashes for an intent and its components.
Parameters:
  • intent: Intent to hash
Returns: Object containing three hashes:
  • routeHash: Keccak256 hash of encoded route
  • rewardHash: Keccak256 hash of encoded reward
  • intentHash: Combined hash of destination, routeHash, and rewardHash
Example:

Vault Address Prediction

intentVaultAddress

Predicts the CREATE2 vault address for an intent.
Parameters:
  • intentSourceAddress: Address of the IntentSource contract
  • intent: Intent object to calculate vault address for
Returns: Predicted vault contract address Example:

Encoding Utilities

Helper functions for encoding common contract function calls.

encodeTransfer

Encodes an ERC20 transfer function call.
Parameters:
  • to: Recipient address
  • value: Amount to transfer
Returns: Encoded calldata for transfer(address,uint256) Example:

encodeTransferNative

Encodes a native token transfer function call.
Parameters:
  • to: Recipient address
  • value: Amount of native tokens to transfer
Returns: Encoded calldata for transferNative(address,uint256)

encodeTransferPayable

Encodes a payable transfer function call.
Parameters:
  • to: Recipient address
  • value: Amount to transfer
Returns: Encoded calldata for transferPayable(address,uint256)

encodeIdentifier

Generates a unique identifier hash from counter and chain ID.
Parameters:
  • counter: Counter value
  • chainid: Chain ID
Returns: Keccak256 hash of encoded counter and chainid Example:

Type Conversion Utilities

The TypeCasts utility class provides functions for converting between Ethereum addresses and bytes32 values.

TypeCasts Class

addressToBytes32

Converts an Ethereum address to bytes32 format.
Parameters:
  • address: Ethereum address (20 bytes)
Returns: bytes32 representation (32 bytes, zero-padded) Example:

bytes32ToAddress

Converts bytes32 back to an Ethereum address.
Parameters:
  • bytes32: bytes32 value (32 bytes)
Returns: Ethereum address (20 bytes, checksummed) Example:

addressesToBytes32Array

Converts multiple addresses to bytes32 array.
Parameters:
  • addresses: Array of Ethereum addresses
Returns: Array of bytes32 values

bytes32ArrayToAddresses

Converts bytes32 array back to addresses.
Parameters:
  • bytes32Array: Array of bytes32 values
Returns: Array of Ethereum addresses

Convenience Functions

All TypeCasts methods are also exported as standalone functions:

ERC-7683 Utilities

Utilities for working with ERC-7683 cross-chain order standard.

Types

Output

Represents a cross-chain output (for maxSpent/minReceived).

OnchainCrosschainOrderData

Order data for on-chain cross-chain intents.

GaslessCrosschainOrderData

Order data for gasless cross-chain intents.

Encoding Functions

encodeOnchainCrosschainOrderData

Encodes on-chain cross-chain order data.

encodeGaslessCrosschainOrderData

Encodes gasless cross-chain order data.

encodeOnchainCrosschainOrder

Encodes a complete on-chain cross-chain order.
Example: