RathRath Finance
How-To GuidesRelay Transactions

Starknet

Submit and track a relay transaction on Starknet.

Starknet is a validity-rollup network that scales Ethereum using STARK proofs. Its contracts are written in Cairo, and calls identify an entrypoint with calldata encoded as field elements.

Follow these steps to submit and track a simple transaction on Starknet.

Import the SDK

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

Initialize the Tachyon Client

const tachyon = new Tachyon({
  apiKey: 'API-KEY',
})

Submit a Transaction

const txId = await tachyon.relay({
  to: '0x021Af6FEc4753c4C7C248Dc68d1B43ed721f0246e9dC8A9e5b7d74Ff3373764B',
  callData: '0x',
  value: '1',
  chainId: 23448594291968334,
  label: 'send strk',
  retries: 0,
})

console.log('Transaction submitted with ID:', txId)

Check Transaction Status

const status = await tachyon.getRelayStatus(txId)
console.log('Transaction status:', status.status)

Wait for Execution

const executedTx = await tachyon.waitForExecutionHash(txId)
console.log('Execution hash:', executedTx.executionTxHash)

Call a Cairo Contract

Compile the entrypoint arguments with starknet.js, represent the call as JSON, and base64-encode it into callData.

import { Tachyon } from '@rathfi/tachyon'
import { CallData, CairoByteArray } from 'starknet'

const contractAddress = '0x02d1b27260a8ce330aa2fdcce3e8b7f7711a02a2c0776511fb5f42390f4216b6'
const name = new CairoByteArray('Hello World')

const calls = [{
  contractAddress,
  entrypoint: 'say_hello',
  calldata: CallData.compile([...name.toApiRequest()]),
}]

const callData = Buffer.from(JSON.stringify(calls), 'utf8').toString('base64')
const tachyon = new Tachyon({ apiKey: 'YOUR_API_KEY' })

const txId = await tachyon.relay({
  chainId: 23448594291968334,
  to: contractAddress,
  value: '0',
  callData,
  label: 'call-contract-starknet',
})
curl -X POST https://tachyon.rath.fi/api/submit-tx \
  -H "api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "chainId": 23448594291968334,
    "to": "0x02d1b27260a8ce330aa2fdcce3e8b7f7711a02a2c0776511fb5f42390f4216b6",
    "value": "0",
    "callData": "W3siY29udHJhY3RBZGRyZXNzIjoiMHgwMmQxYjI3MjYwYThjZTMzMGFhMmZkY2NlM2U4YjdmNzcxMWEwMmEyYzA3NzY1MTFmYjVmNDIzOTBmNDIxNmI2IiwiZW50cnlwb2ludCI6InNheV9oZWxsbyIsImNhbGxkYXRhIjpbIjAiLCIweDQxNmM2OTYzNjUiLCI1Il19XQ==",
    "label": "call-contract-starknet"
  }'

On this page