RathRath Finance
How-To Guides

Smart Contract Call

Learn how to interact with smart contracts using the Tachyon relay API and SDK across multiple chain types.

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

  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:
  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)

Using REST API

Code Example

curl -X POST https://tachyon.rath.fi/api/submit-tx \
  -H "api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "chainId": 8453,
    "to": "0xA7A833e6641D7901F30EaD6f27d4Ee2C9bb670a7",
    "value": "0",
    "callData": "0xc3a9b1c50000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001348656c6c6f2066726f6d2054616368796f6e2100000000000000000000000000",
    "label": "Hello From Tachyon Call"
  }'

Response:

{ "txId": "68fa3450539a3c9d28bbca33" }

Step-by-Step Instructions

  1. Obtain your API key from the Tachyon dashboard at https://accounts.rath.fi

  2. Prepare your contract call data:

    • Identify the target contract address (to)
    • Encode your function call into callData (see SDK example for encoding details)
    • Determine the chainId for your target network (e.g., 8453 for Base, 1 for Ethereum)
  3. Set the transaction value:

    • Use "0" for non-payable functions
    • Specify the amount in wei as a string for payable functions
  4. Make the API request:

    • Send a POST request to https://tachyon.rath.fi/api/submit-tx
    • Include your API key in the api-key header as YOUR_API_KEY
    • Set Content-Type header to application/json
  5. Handle the response:

    • Extract the txId from the response
    • Use this txId to track your transaction status

API Parameters

The RelayParams object defines the parameters required when calling the relay() method.

NameTypeRequiredDescription
chainIdnumberYesThe blockchain network ID where the transaction will be executed. Must be a supported chain.
tostringYesThe recipient wallet address or smart contract address. Format varies by chain (hex for EVM, base58 for Solana, named for NEAR).
callDatastringYesEncoded transaction data in hexadecimal format (use '0x' for simple transfers).
valuestringNoAmount of native currency to send in the smallest unit (wei for EVM, lamports for Solana, yoctoNEAR for NEAR). Defaults to '0' if not specified.
labelstringNoOptional human-readable label for easier transaction identification and tracking.
gasLimitstringNoOptional gas limit for the transaction. If not specified, it will be estimated automatically.
gasPricestringNoGas price for legacy transactions. Cannot be used with maxFeePerGas or maxPriorityFeePerGas.
maxFeePerGasstringNoMaximum fee per gas for EIP-1559 transactions. Must be used together with maxPriorityFeePerGas.
maxPriorityFeePerGasstringNoMaximum priority fee per gas for EIP-1559 transactions. Must be used together with maxFeePerGas.
maxUSDnumberNoMaximum cost in USD that you're willing to pay for this transaction.
retriesnumberNoNumber of retry attempts for the transaction. Defaults to 0.
shouldBatchInMulticallbooleanNoWhether to batch this transaction in a multicall operation.
isAuthenticatedTxbooleanNoEnable authenticated relay mode for additional security and verification. Defaults to false.
derivationPathstringNoOptional HD wallet derivation path for transaction signing (useful for multi-account setups).
transactionType"flash" | "authenticated" | "funding-signed" | "flash-blocks"NoType of relay transaction. Defaults to "flash". "flash-blocks" is only supported on Base (8453) and Base Sepolia (84532).
authorizationListAuthorizationListItem[]NoOptional list of authorization entries for delegated transactions or batched operations. Cannot be used with "flash-blocks" transaction type.

Aptos

Using Tachyon SDK

Code Example

import { Tachyon } from '@rathfi/tachyon';

const tachyon = new Tachyon({ apiKey: 'YOUR_API_KEY' });

const functionPayload = {
  function: "0x3690a8173c5f738234d3772621db2923cf283029d0b9a7795038fde6f3fcdabd::hello_tachyon_v2::preview_message",
  typeArguments: [],
  functionArguments: ["GM Tachyon!"]
};

const callData = Buffer.from(JSON.stringify(functionPayload)).toString('base64');

const txId = await tachyon.relay({
  chainId: 88888888,
  to: "0x3690a8173c5f738234d3772621db2923cf283029d0b9a7795038fde6f3fcdabd",
  value: "0",
  callData,
  label: "send-to-aptos",
  gasLimit: "5000"
});

Using REST API

Code Example

  curl -X POST https://tachyon.rath.fi/api/submit-tx \
    -H "api-key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "chainId": 88888888,
      "to": "0x3690a8173c5f738234d3772621db2923cf283029d0b9a7795038fde6f3fcdabd",
      "value": "0",
      "callData": "eyJmdW5jdGlvbiI6IjB4MzY5MGE4MTczYzVmNzM4MjM0ZDM3NzI2MjFkYjI5MjNjZjI4MzAyOWQwYjlhNzc5NTAzOGZkZTZmM2ZjZGFiZDo6aGVsbG9fdGFjaHlvbl92Mjo6cHJldmlld19tZXNzYWdlIiwidHlwZUFyZ3VtZW50cyI6W10sImZ1bmN0aW9uQXJndW1lbnRzIjpbIkdNIFRhY2h5b24hIl19",
      "label": "send-to-aptos",
      "gasLimit": "5000"
    }'

Response:

{ "txId": "68fa3450539a3c9d28bbca33" }

callData Structure (before Base64 encoding)

{
  "function": "0x3690a8173c5f738234d3772621db2923cf283029d0b9a7795038fde6f3fcdabd::hello_tachyon_v2::preview_message",
  "typeArguments": [],
  "functionArguments": ["GM Tachyon!"]
}

Solana

Using Tachyon SDK

Code Example

import { Tachyon, ChainId } from '@rathfi/tachyon';

const tachyon = new Tachyon({ apiKey: 'YOUR_API_KEY' });

// 1. Create callData
const programId = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr";
const payer = "3dQFssz4XLF9LKTTGrqCy4PwDSFiw6QrPwHW5QkvLmw3"; // your wallet pubkey
const memoMessage = "Hello from rath";

// Encode the message as bytes
const instructionData = Buffer.from(memoMessage, "utf8");

// Build the instruction JSON
const message = {
  programId,
  keys: [],
  data: instructionData.toString("base64"),
};

// Encode the JSON to Base64
const callData = Buffer.from(JSON.stringify(message), "utf8").toString("base64");

// 2. relay contract call
const txId = await tachyon.relay({
  chainId: 10100000,
  to: "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr",
  value: "0",
  callData,
  label: "contract-call-solana"
});

Step-by-Step Instructions

Solana SDK integration documentation will be added soon.

SDK Function Parameters

Parameters specific to Solana program calls will be documented upon release.

Using REST API

Code Example

curl -X POST https://tachyon.rath.fi/api/submit-tx \
  -H "api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr",
    "callData": "eyJwcm9ncmFtSWQiOiJNZW1vU3E0Z3FBQkFYS2I5NnFuSDhUeXNOY1d4TXlXQ3FYZ0RMR21mY0hyIiwia2V5cyI6W10sImRhdGEiOiJTR1ZzYkc4Z1puSnZiU0J5WVhSbyJ9",
    "value": "0",
    "chainId": 10100000,
    "label": "call-contract-solana"
  }'

Step-by-Step Instructions

Example integration for Solana will be added soon.
Developers will be able to relay compiled BPF contract calls using the same /api/submit-tx endpoint.

API Parameters

Documentation will be available soon with Solana-specific parameter details.

Sui

Using Tachyon SDK

Code Example

import { Tachyon } from '@rathfi/tachyon';
import { Transaction as SuiTransaction } from '@mysten/sui/transactions';

const PACKAGE_ID = '0xb4ce9c7b45e665ec8a310b7f5507123fa3de79f53917f20b9408cdcb159dcc70';

const tx = new SuiTransaction();

tx.moveCall({
    target: `${PACKAGE_ID}::greeting::new`,
    arguments: [],
});

const txBytes = tx.serialize();
const createGreetingCallData = Buffer.from(txBytes).toString('base64');

const tachyon = new Tachyon({ apiKey: 'YOUR_API_KEY' });

const txId = await tachyon.relay({
  chainId: 897796746,
  to: "0xb4ce9c7b45e665ec8a310b7f5507123fa3de79f53917f20b9408cdcb159dcc70",
  value: "0",
  callData: createGreetingCallData,
  label: "call-contract-sui",
  gasLimit: "1000000"
});

Using REST API

Code Example

curl -X POST https://tachyon.rath.fi/api/submit-tx \
  -H "api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "chainId": 897796746,
    "to": "0xb4ce9c7b45e665ec8a310b7f5507123fa3de79f53917f20b9408cdcb159dcc70",
    "value": "0",
    "callData": "eyJ2ZXJzaW9uIjoxLCJleHBpcmF0aW9uIjpudWxsLCJnYXNDb25maWciOnt9LCJpbnB1dHMiOlt7ImtpbmQiOiJJbnB1dCIsInR5cGUiOiJvYmplY3QiLCJpbmRleCI6MCwidmFsdWUiOiIweDk3ZTAxODMyY2M4MGI4NTBhMTU5YmUwZmNjNjgwY2Q4ZmE2ZmVkYjIzMmI0YmViNmYxOGMyOGI4YTk2YzE3OWMifSx7ImtpbmQiOiJJbnB1dCIsImluZGV4IjoxLCJ2YWx1ZSI6eyJQdXJlIjpbMTksNzIsMTAxLDEwOCwxMDgsMTExLDMyLDEwMiwxMTQsMTExLDEwOSwzMiw4NCw5Nyw5OSwxMDQsMTIxLDExMSwxMTAsMzNdfSwidHlwZSI6InB1cmUifV0sInRyYW5zYWN0aW9ucyI6W3sia2luZCI6Ik1vdmVDYWxsIiwidGFyZ2V0IjoiMHhiNGNlOWM3YjQ1ZTY2NWVjOGEzMTBiN2Y1NTA3MTIzZmEzZGU3OWY1MzkxN2YyMGI5NDA4Y2RjYjE1OWRjYzcwOjpncmVldGluZzo6dXBkYXRlX3RleHQiLCJ0eXBlQXJndW1lbnRzIjpbXSwiYXJndW1lbnRzIjpbeyJraW5kIjoiSW5wdXQiLCJ0eXBlIjoib2JqZWN0IiwiaW5kZXgiOjAsInZhbHVlIjoiMHg5N2UwMTgzMmNjODBiODUwYTE1OWJlMGZjYzY4MGNkOGZhNmZlZGIyMzJiNGJlYjZmMThjMjhiOGE5NmMxNzljIn0seyJraW5kIjoiSW5wdXQiLCJpbmRleCI6MSwidmFsdWUiOnsiUHVyZSI6WzE5LDcyLDEwMSwxMDgsMTA4LDExMSwzMiwxMDIsMTE0LDExMSwxMDksMzIsODQsOTcsOTksMTA0LDEyMSwxMTEsMTEwLDMzXX0sInR5cGUiOiJwdXJlIn1dfV19",
    "label": "call-contract-sui",
    "gasLimit": "1000000"
  }'

Response:

{ "txId": "68fa3450539a3c9d28bbca33" }

callData Structure (before Base64 encoding)

{
  "version": 1,
  "expiration": null,
  "gasConfig": {},
  "inputs": [
    {
      "kind": "Input",
      "type": "object",
      "index": 0,
      "value": "0x97e01832cc80b850a159be0fcc680cd8fa6fedb232b4beb6f18c28b8a96c179c"
    },
    {
      "kind": "Input",
      "index": 1,
      "value": {"Pure": [19, 72, 101, 108, 108, 111, 32, 102, 114, 111, 109, 32, 84, 97, 99, 104, 121, 111, 110, 33]},
      "type": "pure"
    }
  ],
  "transactions": [
    {
      "kind": "MoveCall",
      "target": "0xb4ce9c7b45e665ec8a310b7f5507123fa3de79f53917f20b9408cdcb159dcc70::greeting::update_text",
      "typeArguments": [],
      "arguments": [
        {"kind": "Input", "type": "object", "index": 0, "value": "0x97e01832cc80b850a159be0fcc680cd8fa6fedb232b4beb6f18c28b8a96c179c"},
        {"kind": "Input", "index": 1, "value": {"Pure": [19, 72, 101, 108, 108, 111, 32, 102, 114, 111, 109, 32, 84, 97, 99, 104, 121, 111, 110, 33]}, "type": "pure"}
      ]
    }
  ]
}

NEAR

Using Tachyon SDK

Code Example

import { Tachyon } from '@rathfi/tachyon';

const tachyon = new Tachyon({ apiKey: 'YOUR_API_KEY' });

const methodCall = {
  methodName: "set_greeting",
  args: {
    greeting: "Hello from tachyon!"
  }
};

const callData = Buffer.from(JSON.stringify(methodCall)).toString('base64');

const txId = await tachyon.relay({
  chainId: 7777777,
  to: "rathgreeting.near",
  value: "0",
  callData,
  label: "contract-call-near"
});

Using REST API

Code Example

curl -X POST https://tachyon.rath.fi/api/submit-tx \
  -H "api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "chainId": 7777777,
    "to": "rathgreeting.near",
    "value": "0",
    "callData": "eyJtZXRob2ROYW1lIjoic2V0X2dyZWV0aW5nIiwiYXJncyI6eyJncmVldGluZyI6IkhlbGxvIGZyb20gdGFjaHlvbiEifX0=",
    "label": "contract-call-near"
  }'

Response:

{ "txId": "68fa3450539a3c9d28bbca33" }

callData Structure (before Base64 encoding)

{
  "methodName": "set_greeting",
  "args": {
    "greeting": "Hello from tachyon!"
  }
}

Starknet

Using Tachyon SDK (TypeScript)

Code Example

  import { CallData, CairoByteArray } from "starknet";

  /**
  * Script to create calldata for say_hello function in Starknet contract
  * Contract: 0x038f1247ea37e673b432794cfa8ebf4561abd0acb98ba4d726e2d15998a9013e
  * Function: say_hello(name: ByteArray) -> ByteArray
  */

  // Create call object for say_hello function
  function createCallObject(contractAddress, name) {
      const nameEncoded = new CairoByteArray(name);
      const calldata = CallData.compile([
          ...nameEncoded.toApiRequest(),
      ]);
      
      return [
          {
              contractAddress: contractAddress,
              entrypoint: 'say_hello',
              calldata,
          },
      ];
  }

  // Encode to base64 for API
  function encodeCallDataToBase64(contractAddress, name) {
      const callObject = createCallObject(contractAddress, name);
      const jsonString = JSON.stringify(callObject);
      return Buffer.from(jsonString, 'utf8').toString('base64');
  }

  // ========== EXAMPLE USAGE ==========

  const CONTRACT_ADDRESS = '0x02D1B27260A8CE330aA2FDCCE3E8B7F7711A02A2C0776511fb5f42390f4216B6';

  // Example name to pass to say_hello function
  const name = 'Hello World';

  // Encode
  const base64CallData = encodeCallDataToBase64(CONTRACT_ADDRESS, name);

  // Initialize SDK
  const tachyon = new Tachyon({ apiKey: 'YOUR_API_KEY' });

  // Relay transaction
  const txId = await tachyon.relay({
    to: "0x02d1b27260a8ce330aa2fdcce3e8b7f7711a02a2c0776511fb5f42390f4216b6",
    callData: base64CallData,
    value: "0",
    chainId: 23448594291968334
  });

  console.log("Transaction ID:", txId);

Step-by-Step Instructions

  1. Install the required dependencies:
  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)

Using REST API

Code Example

curl -X POST https://tachyon.rath.fi/api/submit-tx \
  -H "api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "0x02d1b27260a8ce330aa2fdcce3e8b7f7711a02a2c0776511fb5f42390f4216b6",
    "callData": "W3siY29udHJhY3RBZGRyZXNzIjoiMHgwMmQxYjI3MjYwYThjZTMzMGFhMmZkY2NlM2U4YjdmNzcxMWEwMmEyYzA3NzY1MTFmYjVmNDIzOTBmNDIxNmI2IiwiZW50cnlwb2ludCI6InNheV9oZWxsbyIsImNhbGxkYXRhIjpbIjAiLCIweDQxNmM2OTYzNjUiLCI1Il19XQ==",
    "value": "0",
    "chainId": 23448594291968334
  }'

Response:

{ "txId": "68fa3450539a3c9d28bbca33" }

Step-by-Step Instructions

  1. Obtain your API key from the Tachyon dashboard at https://accounts.rath.fi

  2. Prepare your contract call data:

    • Identify the target contract address (to)
    • Encode your function call into callData (see SDK example for encoding details)
    • Determine the chainId for your target network (e.g., 8453 for Base, 1 for Ethereum)
  3. Set the transaction value:

    • Use "0" for non-payable functions
    • Specify the amount in wei as a string for payable functions
  4. Make the API request:

    • Send a POST request to https://tachyon.rath.fi/api/submit-tx
    • Include your API key in the api-key header as YOUR_API_KEY
    • Set Content-Type header to application/json
  5. Handle the response:

    • Extract the txId from the response
    • Use this txId to track your transaction status

API Parameters

The RelayParams object defines the parameters required when calling the relay() method.

NameTypeRequiredDescription
chainIdnumberYesThe blockchain network ID where the transaction will be executed. Must be a supported chain.
tostringYesThe recipient wallet address or smart contract address. Format varies by chain (hex for EVM, base58 for Solana, named for NEAR).
callDatastringYesEncoded transaction data in hexadecimal format (use '0x' for simple transfers).
valuestringNoAmount of native currency to send in the smallest unit (wei for EVM, lamports for Solana, yoctoNEAR for NEAR). Defaults to '0' if not specified.
labelstringNoOptional human-readable label for easier transaction identification and tracking.
gasLimitstringNoOptional gas limit for the transaction. If not specified, it will be estimated automatically.
gasPricestringNoGas price for legacy transactions. Cannot be used with maxFeePerGas or maxPriorityFeePerGas.
maxFeePerGasstringNoMaximum fee per gas for EIP-1559 transactions. Must be used together with maxPriorityFeePerGas.
maxPriorityFeePerGasstringNoMaximum priority fee per gas for EIP-1559 transactions. Must be used together with maxFeePerGas.
maxUSDnumberNoMaximum cost in USD that you're willing to pay for this transaction.
retriesnumberNoNumber of retry attempts for the transaction. Defaults to 0.
shouldBatchInMulticallbooleanNoWhether to batch this transaction in a multicall operation.
isAuthenticatedTxbooleanNoEnable authenticated relay mode for additional security and verification. Defaults to false.
derivationPathstringNoOptional HD wallet derivation path for transaction signing (useful for multi-account setups).
transactionType"flash" | "authenticated" | "funding-signed" | "flash-blocks"NoType of relay transaction. Defaults to "flash". "flash-blocks" is only supported on Base (8453) and Base Sepolia (84532).
authorizationListAuthorizationListItem[]NoOptional list of authorization entries for delegated transactions or batched operations. Cannot be used with "flash-blocks" transaction type.

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.

On this page