Zebec Network
  • 💰Zebec Network
  • ➡️ZBC to ZBCN Migration Guide
  • 🗞️Zebec Network white Paper
  • 📈ZBCN Tokemonics
  • 🥳Getting Started
    • How to get started?
    • Benefits of Using Zebec Protocol
    • Deposit
    • Start Streaming
    • Withdraw Funds
  • 👾Safe
    • Create Safe
    • Deposit in Safe
    • Sending a Transaction
    • Zapps
    • Signing a Transaction
  • ZEBEC SOLANA
    • 🖥️Zebec Solana Sdk
      • 🖱️Streaming
        • Initialize Zebec Stream
        • Create Fee Vault
        • Update Fee Vault
        • Collect Fees
        • Deposit
        • Withdraw Deposited Token
        • Start Streaming
        • Pause Stream
        • Resume Stream
        • Cancel Stream
        • Withdraw Streamed Token
  • ZEBEC SILVER CARD
    • 💳Silver Card Sdk
      • 🔧Installation
      • 👨‍🚀Quick Start
      • ✉️Fetch Quote
      • ⚖️Configuration Parameters
      • 📦Recipient Fields
      • 🔁Responses
      • 🔢Environment Variables
      • 🌎Supported Countries
  • Zebec Bridge
    • Bridge Sdk
      • Creating clients
      • Initialize Proxy Account
      • Initialize Token Account
      • Deposit
        • Token Transfer
        • Deposit to Zebec
      • Withdraw Deposited
        • Withdraw From Zebec
        • Token Transfer
      • Init Stream
      • Pause/Resume Stream
      • Cancel Stream
      • Update Stream
  • Zebec Near
    • Zebec Near Sdk
      • Normal Stream
        • Initialize Near Stream
        • Initialize Token Stream
        • Pause/Resume Stream
        • Withdraw Stream
        • Update Stream
        • Cancel Stream
        • Claim Stream
        • View methods
      • Multisig Factory
        • Create Multisig Account
      • Multisig Stream
        • Initialize Near Stream
        • Initialize Token Stream
        • Pause/Resume Stream
        • Withdraw Stream
        • Update Stream
        • Cancel Stream
        • Claim Stream
        • View methods
  • ZEBEC EVM
    • Zebec Evm Sdk
      • Zebec Stream Client
        • Creating Clients
        • Whitelisting Tokens
        • Deposit into Zebec Wallet
        • Withdraw from Zebec Wallet
        • Initiating a Stream
        • Pause/Resume/Cancel Stream
        • Updating a Stream
        • Withdraw Streamed Tokens
        • Getting Stream Details
        • Whitelisted Tokens on BSC and Nautilus
      • Zebec Bulk Client
        • Bulk Instant Transfer
      • Zebec Multisig Stream
        • NFT
    • Zapps Compatible
Powered by GitBook
On this page
  1. Zebec Bridge
  2. Bridge Sdk

Initialize Token Account

Creating a token account from Solana Proxy Account for each x-chain users.

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.

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.

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.

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.

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,
);
PreviousInitialize Proxy AccountNextDeposit

Last updated 1 year ago