transferFromEth()

Initiates transaction to transfer tokens to the contract on EVM

Method Parameters

tokenBridgeAddress: string

Ethereum bridge contract address

signer: ethers.Signer

ethers js Signer

tokenAddress: string

Ethereum token address

amount: ethers.BigNumberish

Amount to be bridged (ethers js BigNumberish)

recipientChain: ChainId | ChainName

Destination chain

recipientAddress: Uint8Array

Destination address

network: string

network to use ("WORMHOLE"/"MESSINA")

Returns

Returns ethers js ethers.ContractReceipt

Usage

import { ethers } from "ethers";
import algosdk, { Account, Algodv2 } from "algosdk";
import { approveEth, transferFromEth, CHAIN_ID_ALGORAND } from "@algo-foundry/messina-sdk";

const client: algosdk.Algodv2 = new Algodv2(<ALGO_TOKEN>, <ALGO_ADDRESS>, <ALGOD_PORT>);
const wallet: Account = algosdk.mnemonicToSecretKey(<ALGO_MNEMONIC>)

const provider = new ethers.providers.WebSocketProvider(<ETH_NODE_URL>) as any;   
const signer = new ethers.Wallet(<ETH_PRIVATE_KEY>, provider);

const allowance: ethers.BigNumber = await getAllowanceEth("0xf72a04B891bA46819D83c75687d31f22f6d646c1","0xbF0482884043B7ea1eB55516770C217C77CC7A48", signer);

if(allowance.lt(AMOUNT_TO_TRANSFER)){
  await approveEth(
    "0xf72a04B891bA46819D83c75687d31f22f6d646c1",
    "0xbF0482884043B7ea1eB55516770C217C77CC7A48",
    signer,
    AMOUNT_TO_TRANSFER
  );
}

const receipt: ethers.ContractReceipt = await transferFromEth(
      "0xf72a04B891bA46819D83c75687d31f22f6d646c1",
      signer, 
      "0xbF0482884043B7ea1eB55516770C217C77CC7A48",
      BigInt(10000000), // AMOUNT_TO_TRANSFER * (10 ^ ASSET_DECIMALS)
      CHAIN_ID_ALGORAND,
      algosdk.decodeAddress(wallet.addr).publicKey,
      "WORMHOLE"
  );

Last updated