10. Example B: an ERC-20 token from PulseChain to Ethereum, delivery off

The full file is examples/example-b-token-pulsechain-to-ethereum.ts. The token is PulseX (PLSX), which is native to PulseChain.

const assetLink = await tokenBridgeInfo({
  bridgeKey: [Providers.PULSECHAIN, Chains.PLS, Chains.ETH],
  assetIn: plsx,
  isProd: true,
  fromChainClient: pulsechainClient,
  toChainClient: ethereumClient,
});

assetLink.assetOutAddress is the token's address on Ethereum. A null value is a normal answer: the token has not crossed before, and the first transfer creates it. The example stops there, because the search needs a destination address.

Then the example calls searchBridgeRoutes with PulseChain as the origin and Ethereum as the destination. It picks the served route that has one section whose hop is the omnibridge (plan.hops[0].edge.carrier === Providers.PULSECHAIN).

Step 2: plan with delivery off

const plan = await planCandidateExecution({
  candidate: crossing.candidate,
  account: signer.address,
  readAllowance: chainAccess.readAllowance,
  resolveToken: search.resolveToken,
  sections: [
    {
      amountIn: amount,
      recipient: signer.address,
      omnibridge: { isProd: true, assetLink, delivery: { shouldDeliver: false }, unwrap: false },
    },
  ],
});

The plan is approve and then bridge (relayTokens), both on PulseChain. The approval is for the exact amount, to the PulseChain mediator. The plan skips it when the allowance covers the amount. plan.deliveries is [{ legIndex: 0, status: 'not-requested' }].

With delivery off, nobody is paid to release the tokens on Ethereum. The user claims them there and pays the Ethereum gas. Leaving PulseChain over Ethereum also costs the bridge fee. Read it with loadBridgeFees.

Step 3: poll until claimable

const ready = await waitForTransferStatus({
  source: { chainId: 369, txHash: bridgeHash },
  statusOptions: { signal, originClient: chainAccess.originReaderFor(369) },
  isDone: (status) => status.claimable || status.state === 'delivered',
  intervalMs: 30_000,
});

With delivery off, the ready state is ready-your-turn. If the state is already delivered, somebody else released the tokens, and there is nothing to claim.

Step 4: build the claim, and handle every refusal

The example reads the record with fetchClaimRecords. The function lowercases the hash for you, and asks for exactly the fields a claim reads:

const records = await fetchClaimRecords({ source: { chainId: 369, txHash: bridgeHash }, signal });
const [request] = records; // a plain relayTokens starts exactly one request
const claim = buildClaimTransaction({ request, via: { kind: 'direct' } });

The example stops with an error unless the transaction started exactly one request.

via: { kind: 'direct' } sends the claim straight to the Ethereum bridge and pays no tip. That is correct with delivery off. The router choice is for a request that carries a delivery fee.

The example maps each refusal to an action in an exhaustive switch. A new refusal reason in a later version fails the typecheck:

  • already-delivered: done. Poll until delivered to get destinationTxHash.
  • not-signed-yet: wait 30 seconds and read the record again. This can happen when the status and the record are read a moment apart.
  • signatures-incomplete, wrong-type, malformed-request: stop with a ClaimRefusedError. Do not retry.

Step 5: send the claim on Ethereum

claim.transaction.chainId is 1. The example sends it through the same signer, waits for the receipt, and polls fetchTransferStatus until delivered. destinationTxHash is then the transaction of the claim.