Algorand -> Ethereum

Example bridging from Algorand to Ethereum

Code Flow

Steps

  1. transferFromAlgorand()

  2. signSendAndConfirmTransaction()

  3. getEmitterAddressAlgorand()

  4. ParseSequenceFromLogAlgorand()

  5. getSignedVAA()

  6. redeemOnEth()

1. transferFromAlgorand()

const transferTxs = await transferFromAlgorand(
      algoClient, // Algodv2 from algosdk
      BigInt(114976173),
      BigInt(114976156),
      SENDER_ADDRESS,
      BigInt(105449176),
      BigInt(10000000), // AMOUNT_TO_TRANSFER * (10 ^ ASSET_DECIMALS)
      RECEIVER_ADDRESS,
      CHAIN_ID_ETH,
      BigInt(0)
    );

2. signSendAndConfirmTransaction()

async function signSendAndConfirmAlgorand(
  algodClient: Algodv2, // Algodv2 from algosdk
  txs: TransactionSignerPair[],
  wallet: Account, // Account from algosdk
  waitRounds = 1
) {
  assignGroupID(txs.map((tx) => tx.tx));
  const signedTxns: Uint8Array[] = [];
  for (const tx of txs) {
    if (tx.signer) {
      signedTxns.push(await tx.signer.signTxn(tx.tx));
    } else {
      signedTxns.push(tx.tx.signTxn(wallet.sk));
    }
  }
  await algodClient.sendRawTransaction(signedTxns).do();

  const result = await waitForConfirmation(
    algodClient,
    txs[txs.length - 1].tx.txID(),
    waitRounds
  );
  return result;
}

await signSendAndConfirmAlgorand(
      client,
      transferTxs,
      wallet,
      4
    );

3. getEmitterAddressAlgorand()

const emitterAddr = getEmitterAddressAlgorand(BigInt(114976173));

4. parseSequenceFromLogAlgorand()

const sequence = await parseSequenceFromLogAlgorand(transferResult);

5. getSignedVAA()

let signedVAA = await getSignedVAA(GUARDIAN_GRPC, emitterAddr, 'CHAIN_ID_ALGORAND', sequence, 1000, 5);    

6. redeemOnEth()

const redeem = await redeemOnEth(
      "0xf72a04B891bA46819D83c75687d31f22f6d646c1",
      signer, // Wallet from ethers js
      vaaBytes // parsed signed vaa
    );

Last updated