# Initialize Token Account

For any tokens to migrate from evm chain to solana chain a user must have an existing token account in solana chain. This is becuase, every token has separate associated token account and a user may own many token account. An associated token account address is derived from the token mint address, user wallet address and token program id.

You can create a token account in following way.

```typescript
const owner = "0x91845D534744Ef350695CF98393d23acC9639024";
const tokenAddress = "<evm token address>"
const sourceChain = CHAIN_ID_BSC;
const targetChain = CHAIN_ID_SOLANA;

const tokenAddrInSolana = await getTargetAsset(
   signer, 
   tokenAddress, 
   sourceChain, 
   targetChain
)	
const proxyAccount = ZebecSolBridgeClient.getProxyUserKey(
   tryNativeToUint8Array(owner, sourceChain), 
   sourceChain, 
   SOL_ZEBEC_BRIDGE_ADDRESS
);

const ethClient = new ZebecEthBridgeClient(BSC_ZEBEC_BRIDGE_ADDRESS, signer, sourceChain);

const receipt = await ethClient.createTokenAccount(owner, tokenAddrInSolana);
```

Now you can find signed Vaa bytes of your payload sent to wormhole.

```typescript
const sequence = parseSequenceFromLogEth(receipt, getBridgeAddressForChain(sourceChain));
const zebecEmitterAddress = getEmitterAddressEth(BSC_ZEBEC_BRIDGE_ADDRESS);
const { vaaBytes } = await getSignedVAAWithRetry(WORMHOLE_RPC_HOSTS, sourceChain, zebecEmitterAddress, sequence);
```

Rest of work is performed by the relayer. If you want to manually relay the payloads to solana, you can accomplish it in following way.

```typescript
const payerAddress = wallet.publicKey.toString();
const bridgeAddress = getBridgeAddressForChain(targetChain);

const vaaBuf = Buffer.from(vaaBytes);

setDefaultWasm("node"); // use bundler for browser

// posting vaa in solana
await postVaaSolanaWithRetry(
   connection,
   wallet.signTransaction,
   bridgeAddress,
   payerAddress,
   vaaBuf,
   MAX_VAA_UPLOAD_RETRIES_SOLANA,
);
```

Then you parse payload information from vaa and call method in Zebec Solana bridge program to initialize token account in solana.

```typescript
const { parse_vaa } = await importCoreWasm();
const parsedVaa = parse_vaa(vaaBytes);
const parsedPayload = parseZebecPayload(Buffer.from(parsedVaa.payload));

const result = await solanaClient.initiallizePdaTokenAccount(
   vaaBytes,
   <InitializeTokenAccountPayload>parsedPayload,
);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zebec.io/zebec-bridge/bridge-sdk/initialize-token-account.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
