Git Product home page Git Product logo

oft-transfer-script's Introduction

OFT Token Transfer Script

This script is designed to interact with the OFT smart contract to facilitate token transfers using estimateFees() and sendFrom().

  • estimateFees(): This function provides an estimate of the fees required to send a certain amount of tokens.
  • sendFrom(): This function allows you to send tokens from one address on the source blockchain to another on the destination.

Usage

npx hardhat sendFrom --qty 100000000000000 --network avalanche

Prerequisites

Ensure that you have Node.js and npm installed.

Initialization

Clone the repository and navigate to the hardhat folder: cd hardhat. Install the required npm packages by running:

npm install

Create a .env file in the root directory of the repository and add the following variables:

RPC_ENDPOINT=<Your_RPC_Endpoint_URL>
PRIVATE_KEY=<Your__Private_Key>

RPC_ENDPOINT: This should be the URL of your Ethereum JSON RPC endpoint. PRIVATE_KEY: The private key of the Ethereum address you intend to use with the script.

Running the Script

To test the script on the Avalanche network:

npx hardhat sendFrom --qty 100000000000000 --network avalanche

This will initiate the token transfer, estimate the fees, and log the transaction details.

function sendFrom(
    address _from, // sender
    uint16 _dstChainId, // destination endpoint id
    bytes memory _toAddress, // receiver address
    uint256 _amount, // amount of tokens in wei units
    address payable _refundAddress, // refund address
    address _zroPaymentAddress, // ZRO payment address
    bytes memory _adapterParams, // relayer adapter parameters
    uint256 // unused parameter
  ) public payable virtual override {
    _send(
      _from,
      _dstChainId,
      _toAddress,
      _amount,
      _refundAddress,
      _zroPaymentAddress,
      _adapterParams
    );
  }

To see if your transaction is successful, plug the transaction hash into LayerZero Scan.

How the Script Works

  1. Setup: The script starts by initializing the RPC provider and the wallet using the provided private key.
  2. Contract Initialization: It then imports the ABI for the OFT contract and sets up a contract instance using the provided contract address.
  3. Fee Estimation: Before executing the token transfer, the script estimates the fees associated with the transaction using the estimateSendFee() function of the OFT contract.
  4. Token Transfer: The script calls the sendFrom() function to initiate the token transfer.
  5. Confirmation: It then waits for the transaction to be confirmed and logs the transaction hash.

oft-transfer-script's People

Contributors

st0rmbr3w avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.