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.
Step 1: map the token and search
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
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
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:
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 untildeliveredto getdestinationTxHash.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 aClaimRefusedError. 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.