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.)
SDK
Using Tachyon SDK (TypeScript)
Code Example
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
- Install the required dependencies:
npm install @rathfi/tachyon ethers-
Import the necessary modules:
- Import
TachyonandChainIdfrom@rathfi/tachyon - Import
ethersfor encoding contract call data
- Import
-
Initialize the Tachyon SDK:
- Create a new
Tachyoninstance - Pass your API key in the configuration object:
{ apiKey: 'YOUR_API_KEY' }
- Create a new
-
Define your contract ABI:
- Create an array with the function signature(s) you want to call
- Example:
["function sayHello(string message)"]
-
Encode the function call:
- Create an ethers
Interfaceinstance with your ABI - Use
encodeFunctionData()to encode the function name and parameters - Store the result in
callData
- Create an ethers
-
Submit the relay transaction:
- Call
tachyon.relay()with the transaction parameters - Use
awaitsince this is an asynchronous operation
- Call
-
Handle the transaction ID:
- The method returns a
txIdstring - Use this ID to track the transaction status through the Tachyon API
- The method returns a
SDK Function Parameters
tachyon.relay(options)
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
chainId | ChainId or number | Yes | Chain identifier (use ChainId enum or number) | ChainId.BASE or 8453 |
to | string | Yes | Target contract address | "0xA7A833e6641D7901F30EaD6f27d4Ee2C9bb670a7" |
value | string | Yes | Amount in wei | "0" |
callData | string | Yes | Encoded function call data | Result from iface.encodeFunctionData() |
label | string | Optional | Custom transaction label | "Say Hello Example" |
gasLimit | string | Optional | Gas limit override | "100000" |
isAuthenticatedTx | boolean | Optional | Authenticated relay mode | true or false |
transactionType | string | Optional | Processing 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:
- Submission: The
/api/submit-txendpoint returns a uniquetxId - Queued: Transaction enters the relay queue with
NOT_PICKED_UPstatus - Processing: A relay node picks up and broadcasts the transaction to the blockchain
- 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.