constdepositor=signer.address;constsourceChain=CHAIN_ID_BSC;constdepositorAddrInSolana=ZebecSolBridgeClient.getProxyUserKey( depositor, sourceChain,SOL_ZEBEC_BRIDGE_ADDRESS);consttokenAddress="<evm address of token>";// use ui value for amountconstamount="1";// this may vary depending upon the token being transferedconstrelayFee="0.1";// transfer from evm to solanaconsttransferReceipt=awaittransferEvm( signer, tokenAddress, sourceChain, amount, targetChain,proxyAccount.toString(), relayFee,);
Note: The solana proxy address that is derived from the user's evm address must be initialized beforehand. To initialize see initialize proxy account part.
After this, it takes some time for your token to reach solana chain. During this time, a vaa is created which is then verified and signed by the wormhole validators called guardians. You can obtain the vaa in following way.
The vaa then can be used to posted on solana chain and redeem the token transferred. Zebec provides specialized token bridge relayer supporting certain tokens as well that automatically relay your tokens using small amount of fee so this part may be optional. However, if you want to manually relay you can accomplish it in following way.
constpayerAddress=wallet.publicKey.toString();constbridgeAddress=getBridgeAddressForChain(targetChain);constvaaBuf=Buffer.from(vaaBytes);setDefaultWasm("node"); // use bundler for browser// posting vaa in solanaawaitpostVaaSolanaWithRetry( connection,wallet.signTransaction, bridgeAddress, payerAddress, vaaBuf,MAX_VAA_UPLOAD_RETRIES_SOLANA,);// redeeming tokenconstunsignedTransaction=awaitredeemOnSolana( connection, bridgeAddress, tokenBridgeAddress, payerAddress, vaaBytes,);unsignedTransaction.partialSign(keypair);consttxid=awaitconnection.sendRawTransaction(unsignedTransaction.serialize());awaitconnection.confirmTransaction(txid);
If vaa is supposed to be relayed and token is redeemed by a relayer, in that case you can check and wait for token to be redeemed by the relayer in following way.
let success =false;let retry =0;while(!success) { success =awaitgetIsTransferCompletedSolana(tokenBridgeAddress, transferVaa, connection);awaitnewPromise((r) =>setTimeout(r,5000)); if (retry >13) thrownewError("Transfer failed!"); retry++;}console.log("transfer successful");