Skip to main content

Integration Guide

Integrate taoflash relay into your application to protect transactions from MEV attacks.

Flow

Each step is independent — implement signing however you want (browser wallet, backend keypair, hardware wallet).

Step 1: Prepare

Request transaction parameters from the relay.

curl -X POST https://relay.taoflash.com/prepare \
-H "Content-Type: application/json" \
-d '{
"address": "5FKuRKBzdjNdFuivUNScGgc9i7xBLeMrMVAqdBT7fpULRfx8",
"call_module": "subtensorModule",
"call_function": "addStakeLimit",
"call_params": {
"hotkey": "5Ecr9sKq81UqBfXHpcMvyv8NBikujwJ5yGSPzskqRVLrAdkL",
"netuid": 1,
"amount_staked": 1000000000,
"limit_price": 999999999999,
"allow_partial": false
}
}'

Response:

{
"call_module": "subtensorModule",
"call_function": "addStakeLimit",
"call_params": { ... },
"era": "0x4503",
"nonce": "0x0c",
"blockHash": "0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3"
}

Step 2: Sign

Sign using the parameters from Step 1. This step depends on your wallet implementation.

Browser Wallet (Polkadot.js)

import { web3FromSource } from '@polkadot/extension-dapp'

const injector = await web3FromSource(account.meta.source)
const params = Object.values(prepareData.call_params)
const extrinsic = api.tx[prepareData.call_module][prepareData.call_function](...params)

const signedExtrinsic = await extrinsic.signAsync(account.address, {
signer: injector.signer,
era: prepareData.era,
nonce: prepareData.nonce,
blockHash: prepareData.blockHash
})

const signedHex = signedExtrinsic.toHex()

Backend Keypair (TypeScript)

import { Keyring } from '@polkadot/keyring'

const keyring = new Keyring({ type: 'sr25519' })
const pair = keyring.addFromUri(process.env.MNEMONIC)

const params = Object.values(prepareData.call_params)
const extrinsic = api.tx[prepareData.call_module][prepareData.call_function](...params)

const signedExtrinsic = extrinsic.sign(pair, {
era: prepareData.era,
nonce: prepareData.nonce,
blockHash: prepareData.blockHash
})

const signedHex = signedExtrinsic.toHex()

Backend Keypair (Python)

Using py-substrate-interface:

from substrateinterface import SubstrateInterface, Keypair

# Connect to Bittensor
substrate = SubstrateInterface(
url="wss://entrypoint-finney.opentensor.ai:443"
)

# Create keypair from mnemonic
keypair = Keypair.create_from_mnemonic("your mnemonic here")

# Compose the call
call = substrate.compose_call(
call_module=prepare_data['call_module'],
call_function=prepare_data['call_function'],
call_params=prepare_data['call_params']
)

# Create signed extrinsic with relay parameters
extrinsic = substrate.create_signed_extrinsic(
call=call,
keypair=keypair,
era=prepare_data['era'],
nonce=int(prepare_data['nonce'], 16) if isinstance(prepare_data['nonce'], str) else prepare_data['nonce']
)

# Get the signed hex
signed_hex = '0x' + extrinsic.data.hex()

Step 3: Queue

Submit the signed transaction to the relay.

curl -X POST https://relay.taoflash.com/queue \
-H "Content-Type: application/json" \
-d '{"signed_extrinsic": "0x45028400..."}'

Response:

{
"tx_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}

Step 4: Poll Status

Poll until the transaction is confirmed or failed.

curl https://relay.taoflash.com/status/a1b2c3d4-e5f6-7890-abcd-ef1234567890

Transaction States

StateDescription
queuedWaiting for optimal submission block
submittedSubmitted to Bittensor network
confirmedIncluded in block and validated
failedTransaction failed

Error Handling

Transaction Failed

Check status.error and status.validation for details:

if (status.status === 'failed') {
const error = status.validation?.error || status.error
console.error('Transaction failed:', error)
}

Compatible Wallets

Any Polkadot-compatible wallet works with taoflash relay:

  • Talisman - Recommended for best UX
  • Bittensor Wallet - Official Bittensor wallet
  • Polkadot.js Extension - Developer favorite
  • SubWallet - Mobile-friendly option

Notes

  • Parameter names can use either camelCase or snake_case
  • No authentication required for relay endpoints
  • See Supported Transactions for all available transaction types