# How to bridge from BSC

This guide shows you how to bridge USDC from BSC with Fast Bridge. USDC on BSC has no EIP-3009 support, so you sign a Permit2 transfer instead. To bridge from another EVM chain, see [How to bridge to a recipient](/guides/how-to/fast-bridge/bridge-tokens) instead.

## Prerequisites

* A Pimlico API key with Fast Bridge enabled.
* An account holding USDC on BSC, and enough BNB for one approval.

:::code-group
```bash [npm]
npm install viem
```

```bash [pnpm]
pnpm install viem
```

```bash [bun]
bun install viem
```
:::

## Steps

::::steps
### Set up a bridge client

Create the account and the functions that call the Fast Bridge API: one to get a chain's [bridge addresses](/references/fast-bridge/endpoints#get-addresseschain), and one to bridge the tokens.

:::code-group
```ts [main.ts]
import {
	type Address,
	createWalletClient,
	erc20Abi,
	type Hex,
	http,
	maxUint256,
	parseUnits,
	publicActions,
	toHex,
} from "viem"
import { privateKeyToAccount } from "viem/accounts"
import { arbitrum, bsc } from "viem/chains"
import type {
	BridgeAddresses,
	BridgeRequest,
	BridgeStatus,
	Permit2Authorization,
} from "./types"

const apiKey = "YOUR_PIMLICO_API_KEY"

const PERMIT2: Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3"
const USDC_BSC: Address = "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d" // 18 decimals
const USDC_ARBITRUM: Address = "0xaf88d065e77c8cC2239327C5EDb3A432268e5831"

// The account that holds the USDC on the origin chain
const user = privateKeyToAccount(process.env.USER_PRIVATE_KEY as Hex)

// Throws the bridge's { code, message } if it rejected the request
const readResponse = async (response: Response) => {
	const body = await response.json()
	if (!response.ok) {
		throw new Error(`${body.code}: ${body.message}`)
	}
	return body
}

// Who authorizations on a chain are made out to
const getBridgeAddresses = async (
	chainId: number,
): Promise<BridgeAddresses> => {
	const response = await fetch(
		`https://api.pimlico.io/v1/bridge/addresses/${chainId}?apikey=${apiKey}`,
	)
	return readResponse(response)
}

// Bridges the tokens to the recipient and waits for the outcome
const bridgeTokens = async (request: BridgeRequest): Promise<BridgeStatus> => {
	const response = await fetch(
		`https://api.pimlico.io/v1/bridge/execute/sync?apikey=${apiKey}`,
		{
			method: "POST",
			headers: { "Content-Type": "application/json" },
			body: JSON.stringify(request),
		},
	)
	return readResponse(response)
}
```

```ts [types.ts]
import type { Address, Hex } from "viem"

export type BridgeAddresses = { approvalAddress: Address; multicaller: Address }

export type Permit2Authorization = {
	type: "permit2"
	token: Address
	from: Address
	spender: Address
	amount: string
	nonce: string
	deadline: number
	signature: Hex
}

export type BridgeRequest = {
	originChainId: number
	destinationChainId: number
	originToken: Address
	destinationToken: Address
	authorization: Permit2Authorization
	// Defaults to authorization.from
	recipient?: Address
}

export type BridgeStatus = {
	requestId: string
	status: "pending" | "success" | "failed" | "refunded"
	amountIn: string
	fee: string
	amountOut: string
	origin: { chainId: number; status: string; transactionHash?: string }
	destination: {
		chainId: number
		recipient: string
		status: string
		transactionHash?: string
		error?: { code: string; message: string }
	}
}
```
:::

### Approve Permit2

Approve the [Permit2](https://github.com/Uniswap/permit2) contract for the token. The account does this once per token, in a transaction it pays for. Without it, the request is rejected with `INSUFFICIENT_ALLOWANCE`.

```ts
const client = createWalletClient({
	account: user,
	chain: bsc,
	transport: http(),
}).extend(publicActions)

const hash = await client.writeContract({
	address: USDC_BSC,
	abi: erc20Abi,
	functionName: "approve",
	args: [PERMIT2, maxUint256],
})
await client.waitForTransactionReceipt({ hash })
```

### Sign the Permit2 transfer

Sign a Permit2 `PermitTransferFrom` for the amount, with `spender` set to the origin chain's `approvalAddress`. USDC on BSC has 18 decimals, so parse the amount with 18.

```ts
// Authorizations are made out to the origin chain's approvalAddress
const { approvalAddress } = await getBridgeAddresses(bsc.id)

const amount = parseUnits("25", 18) // 25 USDC
const deadline = Math.floor(Date.now() / 1000) + 5 * 60 // 5 minutes
// Permit2 SignatureTransfer nonces are unordered: any unused uint256 works
const nonce = BigInt(toHex(crypto.getRandomValues(new Uint8Array(32))))

const signature = await user.signTypedData({
	domain: { name: "Permit2", chainId: bsc.id, verifyingContract: PERMIT2 },
	types: {
		PermitTransferFrom: [
			{ name: "permitted", type: "TokenPermissions" },
			{ name: "spender", type: "address" },
			{ name: "nonce", type: "uint256" },
			{ name: "deadline", type: "uint256" },
		],
		TokenPermissions: [
			{ name: "token", type: "address" },
			{ name: "amount", type: "uint256" },
		],
	},
	primaryType: "PermitTransferFrom",
	message: {
		permitted: { token: USDC_BSC, amount },
		spender: approvalAddress,
		nonce,
		deadline: BigInt(deadline),
	},
})

const authorization: Permit2Authorization = {
	type: "permit2",
	token: USDC_BSC,
	from: user.address,
	spender: approvalAddress,
	amount: amount.toString(),
	nonce: nonce.toString(),
	deadline,
	signature,
}
```

### Send the request

Send it as a `permit2` authorization, with the origin and destination chains, the tokens and the `recipient`. `bridgeTokens` returns once the bridge has finished, and throws if the request is rejected. See the [error codes](/references/fast-bridge/errors).

```ts
const result = await bridgeTokens({
	originChainId: bsc.id,
	destinationChainId: arbitrum.id,
	originToken: USDC_BSC,
	destinationToken: USDC_ARBITRUM,
	authorization,
	recipient: user.address,
})
```

### Check the result

Read `status` from the response:

* `success`: the USDC was delivered in `destination.transactionHash`.
* `failed`: nothing was bridged, and the USDC is still on the origin chain.
* `pending`: the bridge hasn't finished. See [How to check a bridge's status](/guides/how-to/fast-bridge/track-request).

```ts
if (result.status === "success") {
	console.log("Delivered:", result.destination.transactionHash)
} else if (result.status === "failed") {
	console.log("Nothing was bridged")
} else {
	console.log("Still pending")
}
```
::::

## Related

* [How to bridge to a recipient](/guides/how-to/fast-bridge/bridge-tokens)
* [How to bridge and call contracts](/guides/how-to/fast-bridge/bridge-and-call)
* [Fast Bridge endpoints](/references/fast-bridge/endpoints)
* [Fast Bridge errors](/references/fast-bridge/errors)
