Skip to Content

Smart Contract Call

Use the Tachyon Relay API to interact with smart contracts across multiple blockchains. The /api/submit-tx endpoint supports EVM, Solana, Aptos, Sui, and NEAR, enabling a unified interface for submitting encoded contract calls through the Tachyon network.

Chain Examples

EVM Chains (Ethereum, Base, Polygon, etc.)

Using Tachyon SDK (TypeScript)

Code Example

smart-contract-call.ts
import { Tachyon, ChainId } from '@rathfi/tachyon'; import { ethers } from 'ethers'; // Initialize SDK const tachyon = new Tachyon({ apiKey: 'YOUR_API_KEY' }); // Create and encode the function call const abi = ["function sayHello(string message)"]; const iface = new ethers.Interface(abi); const callData = iface.encodeFunctionData("sayHello", ["Hello from Tachyon!"]); // Relay transaction const txId = await tachyon.relay({ chainId: ChainId.BASE, to: "0xA7A833e6641D7901F30EaD6f27d4Ee2C9bb670a7", value: "0", callData, label: "Say Hello Example" }); console.log("Transaction ID:", txId);

Step-by-Step Instructions

  1. Install the required dependencies:
terminal
npm install @rathfi/tachyon ethers
  1. Import the necessary modules:

    • Import Tachyon and ChainId from @rathfi/tachyon
    • Import ethers for encoding contract call data
  2. Initialize the Tachyon SDK:

    • Create a new Tachyon instance
    • Pass your API key in the configuration object: { apiKey: 'YOUR_API_KEY' }
  3. Define your contract ABI:

    • Create an array with the function signature(s) you want to call
    • Example: ["function sayHello(string message)"]
  4. Encode the function call:

    • Create an ethers Interface instance with your ABI
    • Use encodeFunctionData() to encode the function name and parameters
    • Store the result in callData
  5. Submit the relay transaction:

    • Call tachyon.relay() with the transaction parameters
    • Use await since this is an asynchronous operation
  6. Handle the transaction ID:

    • The method returns a txId string
    • Use this ID to track the transaction status through the Tachyon API

SDK Function Parameters

tachyon.relay(options)

ParameterTypeRequiredDescriptionExample
chainIdChainId or numberYesChain identifier (use ChainId enum or number)ChainId.BASE or 8453
tostringYesTarget contract address"0xA7A833e6641D7901F30EaD6f27d4Ee2C9bb670a7"
valuestringYesAmount in wei"0"
callDatastringYesEncoded function call dataResult from iface.encodeFunctionData()
labelstringOptionalCustom transaction label"Say Hello Example"
gasLimitstringOptionalGas limit override"100000"
isAuthenticatedTxbooleanOptionalAuthenticated relay modetrue or false
transactionTypestringOptionalProcessing type"flash" or "flash-blocks"

Returns: Promise<string> - The transaction ID (txId)


Transaction Lifecycle

After submitting your transaction through either the REST API or SDK:

  1. Submission: The /api/submit-tx endpoint returns a unique txId
  2. Queued: Transaction enters the relay queue with NOT_PICKED_UP status
  3. Processing: A relay node picks up and broadcasts the transaction to the blockchain
  4. Executed: Transaction gets confirmed on-chain; execution hash becomes available

You can use the txId to query the transaction status and retrieve the execution hash once confirmed.


Summary

The Tachyon Relay API provides a simple, unified interface for interacting with smart contracts across multiple blockchain networks. Whether you’re using the REST API for direct HTTP calls or the TypeScript SDK for type-safe integration, the process remains straightforward: encode your contract call, submit it to the relay, and track it using the returned transaction ID.

Last updated on