# Relay bridging with BLOCK CLI

BLOCK CLI version 0.12.0 exposes seven Relay actions through the existing authenticated HTTP API and JSON CLI, including native SOL deposits to EVM destinations. Start with [Solana-first agents](/docs#wallets) to create an encrypted local wallet, fund it on Solana, and connect the hosted API. Read the action schemas before invoking them:

```sh
block-cli platforms relay
block-cli schema relay prepare_bridge_solana
block-cli schema relay prepare_bridge
```

| Action | Scope | Result |
| --- | --- | --- |
| `chains` | `read` | Relay chain catalog, availability flags, native currencies and missing requested chains |
| `currencies` | `read` | Bounded token search or exact address lookup, with provider verification flags |
| `quote` | `read` | Exact-input bridge quote, minimum output, provider fees and request ID; no transaction |
| `prepare_bridge_solana` | `prepare` | Fresh quote and validated unsigned V0 native SOL deposit for an EVM destination |
| `prepare_bridge` | `prepare` | Fresh quote and one validated unsigned native EVM deposit transaction |
| `prepare_bridge_token` | `prepare` | One validated classic-SPL deposit or explicit ERC-20 approval/reset/deposit stage |
| `status` | `read` | Relay-reported intent status, fill/refund/failure distinction and transaction hashes when available |

## Chain and token discovery

```sh
block-cli call relay chains --params '{"chainIds":[1,8453,56,4663,792703809],"limit":20}'
block-cli call relay currencies --params '{"chainIds":[8453],"term":"USDC","verified":true,"limit":10}'
block-cli call relay currencies --params '{"chainIds":[8453],"address":"0x833589fcd6edb6e08f4c7c32d4f71b54bda02913"}'
```

An exact currency lookup requires exactly one chain ID. Token verification is Relay metadata, not an independent asset audit. A chain or currency in the catalog does not guarantee a route. Discovery can return more chains than this gateway's quote/preparation allowlist.

| Network | Relay chain ID | Native currency address |
| --- | --- | --- |
| Ethereum | `1` | `0x0000000000000000000000000000000000000000` |
| Base | `8453` | `0x0000000000000000000000000000000000000000` |
| BNB Chain | `56` | `0x0000000000000000000000000000000000000000` |
| Robinhood Chain | `4663` | `0x0000000000000000000000000000000000000000` |
| Solana | `792703809` | `11111111111111111111111111111111` |

Native SOL uses the system address, not the wrapped SOL mint. ERC-20/SPL currencies use their contract or mint address. All amounts are raw integer strings; the origin currency's decimals determine the human amount.

## Quote a bridge

This public-address example requests an informational quote for 0.01 ETH from Base to Ethereum. It does not move funds. Replace both addresses with the intended payer and recipient for your own route.

```sh
block-cli call relay quote --params '{"user":"0x03508bb71268bba25ecacc8f620e01866650532c","recipient":"0x03508bb71268bba25ecacc8f620e01866650532c","originChainId":8453,"destinationChainId":1,"originCurrency":"0x0000000000000000000000000000000000000000","destinationCurrency":"0x0000000000000000000000000000000000000000","amount":"10000000000000000","slippageBps":50}'
```

`slippageBps: 50` allows 0.5%; the maximum is 500 bps. Only distinct origin/destination chains and `EXACT_INPUT` are supported. The gateway checks the quoted identities, raw input, minimum output, slippage and fee currencies. Quotes expose the required step kinds but omit provider transaction payloads. A quote can describe a flow that this gateway cannot prepare.

## Prepare native SOL → Base

This public-fixture example prepares a 0.1 SOL input for native ETH on Base. It does not move funds. Replace the Solana payer and EVM recipient with addresses controlled by the agent's local wallets; do not fund these example addresses.

```sh
block-cli call relay prepare_bridge_solana --params '{"user":"CnTeYCBA7Hzj9r2s99SaEXKYpiWixtMUkqZWHwyNbm3g","recipient":"0x03508bb71268bba25ecacc8f620e01866650532c","originChainId":792703809,"destinationChainId":8453,"originCurrency":"11111111111111111111111111111111","destinationCurrency":"0x0000000000000000000000000000000000000000","amount":"100000000","slippageBps":50,"maxGasFeeAmount":"2000000"}'
```

`amount` and `maxGasFeeAmount` are raw lamport strings. This example sets a 2,000,000-lamport (0.002 SOL) network-fee ceiling in addition to the 100,000,000-lamport (0.1 SOL) deposit. The ceiling applies separately to Relay's reported gas estimate and the RPC network-fee estimate; the latter already includes the encoded priority fee. These estimates are not added together. Keep enough native SOL for both the deposit and the actual network fee.

`prepare_bridge_solana` accepts native SOL from an on-curve Solana payer to Ethereum, Base, BNB or Robinhood. SPL assets and wrapped SOL are unsupported as origins. The destination currency can be a supported native asset or token; requesting a token does not also fund native gas on that destination. Relay determines current route availability.

The builder fetches a fresh quote and applies the same exact-input, settlement, refund, canonical destination-contract and recomputed order-ID checks as the EVM builder. It then verifies:

- The Solana mainnet genesis, canonical Relay program and vault from separate chain metadata, derived configuration/vault addresses, account owners, executable flags and supported configuration layout.
- The pinned IDL's exact `deposit_native` discriminator, unsigned 64-bit lamport amount, order ID, account order and flags. The requested payer is also the credited depositor and the only signer.
- One bounded compute-unit limit, an optional bounded compute-unit price, and exactly one native deposit. Extra programs, transfers, account creation and altered deposit instructions are rejected. Provider lookup tables are not used.
- A fresh confirmed blockhash and RPC network-fee estimate from contexts at least as recent as the account snapshot. Expired blockhashes, malformed RPC results and fees above the requested ceiling fail explicitly.

The result includes `transactionBase64`, structural `transaction` metadata, `deposit`, verified `protocol` order terms, `validation`, `feeEstimate`, `blockhash`, `lastValidBlockHeight`, context slots, and the Relay `requestId`. The V0 transaction has zero signatures and no lookup tables; `signed` and `broadcast` are `false`. Native deposit preparation creates no accounts and reports `rentChargeLamports: "0"`.

Preparation does not check the wallet balance or simulate the transaction. The local wallet must independently review the encoded spending policy, payer, recipient, amount, order terms and fee budget; check its funds and blockhash expiry; then simulate before signing and submitting. `solana.simulate` accepts the unsigned `transactionBase64`, but simulation is a snapshot and does not prove future execution. Rebuild after blockhash expiry. Use `tx inspect`, `wallet sign`, `tx submit` and `tx status` for the separately approved local execution workflow; keys never go to the hosted API. After submission, track the Relay intent and confirm destination balances before using EVM tools.

## Prepare an unsigned native EVM deposit

Use the same fields plus an explicit `maxGasFeeAmount`, in raw native units of the origin chain. Save the response for independent wallet review:

```sh
block-cli call relay prepare_bridge --params '{"user":"0x03508bb71268bba25ecacc8f620e01866650532c","recipient":"0x03508bb71268bba25ecacc8f620e01866650532c","originChainId":8453,"destinationChainId":1,"originCurrency":"0x0000000000000000000000000000000000000000","destinationCurrency":"0x0000000000000000000000000000000000000000","amount":"10000000000000000","slippageBps":50,"maxGasFeeAmount":"1000000000000000"}'
```

Preparation fetches a fresh quote. It requires one native EVM input, one settlement payment, a supported protocol V1 order, no arbitrary output calls, and one explicit `depositNative` transaction. It compares settlement and refund recipients, requires an origin refund path, recomputes the order ID with Relay's official settlement SDK, checks the canonical depository and settlement contracts from a separate chain-metadata request, and verifies the exact payer, chain, value and calldata. Unsupported approval, signature, token-origin and deposit-address flows fail explicitly. Use the separate `prepare_bridge_solana` action for native SOL origins.

The result includes `transaction`, `protocol`, `validation`, `feeEstimate`, `requestId`, `signed: false` and `broadcast: false`. `maxGasFeeAmount` bounds the provider's gas estimate and `gas × maxFeePerGas`; it is not an all-inclusive L2 fee cap. The external wallet must check current balance, nonce, all L2 data/operator fees, order expiry and transaction simulation before signing or sending. The gateway does not reserve liquidity or a nonce, execute a bridge, or guarantee settlement.

## Track an intent

Pass the Relay `data.requestId` returned by the quote/preparation response. This differs from the outer gateway `requestId`, which is for gateway diagnostics.

```sh
block-cli schema relay status
# Use the actual Relay request ID returned in data.requestId:
block-cli call relay status --params '{"requestId":"YOUR_RELAY_REQUEST_ID"}'
```

`waiting`, `pending`, `submitted`, `depositing` and `delayed` are not successful fills. `success` maps to `filled`; `refund` maps to `refunded`, not destination delivery; `failure` maps to `failed`. Unknown IDs remain `found: false` and `outcome: "unknown"`. Status is provider-reported and not independently verified onchain. Quotes alone do not submit a deposit. Deposit-address order tracking is outside this integration's preparation scope.

## Operator configuration

Set `RELAY_API_KEY` in Railway Variables for authenticated Relay access. It is separate from the gateway access key and remains server-side. Relay's current documentation requires a valid `x-api-key` for `/quote/v2`. Public calls were still accepted during integration checks, but that behavior is not a durable authentication guarantee. A rejected quote credential returns `RELAY_API_KEY_REQUIRED`; never expose a provider key in a browser or CLI parameter.

## Sources and verification

The implementation follows Relay's official [quote API](https://docs.relay.link/references/api/get-quote-v2), [input validation](https://docs.relay.link/references/api/api_core_concepts/input-validation), [Solana guide](https://docs.relay.link/references/api/api_guides/solana), [chain catalog](https://docs.relay.link/references/api/get-chains), [currencies API](https://docs.relay.link/references/api/get-currencies-v2), [intent status](https://docs.relay.link/references/api/get-intents-status-v3), and [API-key documentation](https://docs.relay.link/references/api/api-keys), with the pinned settlement SDK's Solana depository IDL. Tests cover identity tampering, malformed responses, order/calldata binding, Solana instruction/account/signer checks, blockhash and fee limits, authentication and scopes. Live verification uses public fixture addresses and unsigned preparation only.

## Token-origin bridges (v0.12)

`relay.prepare_bridge_token` accepts the same exact-input route fields as the native builders, plus `stage` (`deposit`, `approve`, or `reset_approval`) and `maxRentLamports` for Solana. All protocol-order, recipient, refund, minimum-output, canonical-depository and order-hash checks remain active.

For classic SPL tokens, use `stage: "deposit"`, an on-curve wallet, explicit raw token amount, `maxGasFeeAmount` in lamports and a vault-ATA rent ceiling. The builder reconstructs the canonical Relay `deposit_token` instruction, verifies the wallet/mint/token accounts, simulates exact source and vault token deltas, and bounds SOL fees/rent. Existing source ATAs are required. Token-2022, wrapped SOL token deposits, frozen/delegated accounts and additional instructions are rejected. Use the native SOL action for SOL.

For standard ERC-20 tokens, the builder checks pending allowance and token/native balances and simulates one selected transaction. If allowance is zero, prepare `stage: "approve"`, inspect/sign/submit with the local EVM wallet, confirm it, then request a **fresh** `stage: "deposit"` quote. If an insufficient nonzero allowance exists, first prepare and confirm `stage: "reset_approval"`, then an exact new approval. No unlimited allowance or permit is accepted. The deposit uses the four-argument `depositErc20(depositor, token, amount, orderId)` overload, never the overload that spends the full allowance.

Each response contains only one executable stage. An approval does not bridge funds, can persist after an abandoned bridge, and may need an explicit reset. `maxGasFeeAmount` bounds the selected stage’s execution gas and the reported route estimate; L2 data/operator fees remain additional. Fee-on-transfer/rebasing tokens are unsupported: `eth_call` cannot prove arbitrary token transfer effects. Inspect every stage, confirm prerequisite transactions, rebuild expired quotes, and reconcile both origin confirmation and Relay settlement. All private keys remain local.

Example SPL input:

```json
{
  "user": "<public Solana wallet>",
  "recipient": "<public Base wallet>",
  "originChainId": 792703809,
  "destinationChainId": 8453,
  "originCurrency": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
  "destinationCurrency": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
  "amount": "1000000",
  "slippageBps": 50,
  "maxGasFeeAmount": "100000",
  "maxRentLamports": "3000000",
  "stage": "deposit"
}
```
