Token transfer Ethereum -> Polkadot

A guide on using the Snowbridge TypeScript SDK for integration.

Uses the @snowbridge/api toPolkadotSnowbridgeV2 package to send the transaction. Please ensure you've completed Setup Steps before proceeding with this guide.

Pre-step: Create Transfer Impl

// Select the token you want to send. In this case we use Ether. The registry 
// contains the list of tokens.
const DESTINATION_PARACHAIN = 1000
const TOKEN_CONTRACT = assetsV2.ETHER_TOKEN_ADDRESS
const transferImpl = toPolkadotSnowbridgeV2.createTransferImplementation(
    DESTINATION_PARACHAIN,
    registry,
    TOKEN_CONTRACT
)

Step 1: Get Delivery Fee

Use getDeliveryFee() to calculate how much the user must pay in order to deliver the message across chains. This includes relayer fees and any protocol-specific gas or weight costs. Displaying this to the user upfront ensures clarity and reduces failed transactions due to underpayment.

let fee = await transferImpl.getDeliveryFee(
    context,
    registry,
    TOKEN_CONTRACT,
    DESTINATION_PARACHAIN,
    relayerFee
)

Step 2: Create Transfer

The createTransfer() function generates a transfer object, which includes source and destination accounts, the amount to send, the token being transferred and the precomputed delivery fee. This object contains all data necessary to execute the cross-chain transfer and is later used for validation and signing.

Step 3: Validate Transfer

Although optional, validateTransfer() is strongly recommended. It performs local checks and dry-runs the transaction (when possible) to ensure:

  • The sender has enough funds

  • The asset is supported

  • The constructed transaction will succeed on-chain

This step can save users from wasting gas or fees on transactions that would otherwise revert.

Step 4: Send Transaction

Finally, the transaction is signed and submitted to the source chain. Use the Wallet instance to send the transaction.

Polkadot to Ethereum

Full example: send_ether_from_assethub_to_eth.ts

Uses the @snowbridge/api toEthereumV2 module to send the transaction.

Setup

This step prepares all required state and dependencies for the transfer operation. This includes loading the asset registry, initializing the context, which sets up the connections to Ethereum and Substrate-based networks and loading the user wallets for both Ethereum and Substrate chains.

Step 1: Get Delivery Fee

Use getDeliveryFee() to calculate how much the user must pay in order to deliver the message across chains. This includes relayer fees and any protocol-specific gas or weight costs. Displaying this to the user upfront ensures clarity and reduces failed transactions due to underpayment.

Step 2: Create Transfer

The createTransfer() function generates a transfer object, which includes source and destination accounts, the amount to send, the token being transferred and the precomputed delivery fee. This object contains all data necessary to execute the cross-chain transfer and is later used for validation and signing.

Step 3: Validate Transfer

Although optional, validateTransfer() is strongly recommended. It performs local checks and dry-runs the transaction (when possible) to ensure:

  • The sender has enough funds

  • The asset is supported

  • The constructed transaction will succeed on-chain

This step can save users from wasting gas or fees on transactions that would otherwise revert.

Step 4: Send Transaction

Finally, the transaction is signed and submitted to the source chain. Use the SDK helper signAndSend() which manages construction, signing, and submission of the extrinsic.

Last updated