1.2.4 • Published 2 years ago

parakeet-bridge-sdk v1.2.4

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

What is Parakeet SDK

Parakeet Bridge provides a key missing piece of infrastructure by helping users bridge their NFTs between multiple blockchains. With Parakeet bridge you can transfer your ERC721/ERC1155 tokens across multiple public blockchain networks in a secure, trustless & decentralized manner. You can read more about Parakeet DAO in Official docs NPM package

Supported chains (Testnet)

TestnetChain ID
Rinkeby4
BSC Testnet97
Arbitrum Rinkeby Testnet421611
Mumbai (Polygon Testnet)80001
Fantom Testnet4002
Fuji (Avalanche Testnet)43113
Optimism Kovan Testnet69

Supported chains (Mainnet) >>> Coming Soon

MainnetChain ID
Ethereum1
Binance Smart Chain56
Arbitrum42161
Polygon137
Fantom250
Avalanche43114
Optimism10

How to install

npm i parakeet-bridge-sdk

How to approve the bridge

  1. Import approve function

    import { approve } from 'parakeet-bridge-sdk/src/';
  2. Use inside your project. All arguments are required

    await approve({
      srcChainId,
      nftCollectionAddress,
      tokenId,
      provider,
      account,
    });

Arguments for approve

ArgumentTypeRequiredDescription
srcChainIdIntegertruechain Id on the source chain -> chain on which the NFT is present
nftCollectionAddressStringtruecontract address of collection on the source chain
tokenIdStringtruespecific token Id that you want to bridge
providerObjecttrueWeb3Provider
accountStringtrueaccount address

How to bridge the NFT

  1. Import bridge function

    import { bridge } from 'parakeet-bridge-sdk/src/';
  2. Use inside your project. All arguments are required

    await bridge({
      srcChainId,
      dstChainId,
      nftCollectionAddress,
      tokenId,
      provider,
      account,
    });

Arguments for bridge

ArgumentTypeRequiredDescription
srcChainIdIntegertruechain Id on the source chain -> chain where the NFT is currently present
dstChainIdIntegertruechain Id of the destination chain -> chain where you want to bridge the NFT
nftCollectionAddressStringtruecontract address of collection on the source chain
tokenIdStringtruespecific token Id that you want to bridge
providerObjecttrueWeb3Provider
accountStringtrueaccount address

How to estimate bridge fee

  1. Import estimateBridgeFees function

    import { estimateBridgeFees } from 'parakeet-bridge-sdk/src/';
  2. Use inside your project. All arguments are required

    const estimatedFees = await estimateBridgeFees({
           account,
           dstChainId,
           srcChainId,
           provider,
           tokenId,
           nftSrcContractAddress
         });

Arguments for estimateBridgeFees

ArgumentTypeRequiredDescription
srcChainIdIntegertruechain Id on the source chain -> chain where the NFT is currently present
dstChainIdIntegertruechain Id of the destination chain -> chain where you want to bridge the NFT
nftSrcContractAddressStringtruecontract address of collection on the source chain
tokenIdStringtruespecific token Id that you want to bridge
providerObjecttrueWeb3Provider
accountStringtrueaccount address

Example

ReactJs Example using web3-react

import { approve, bridge } from 'parakeet-bridge-sdk/src/';
import { useWeb3React } from '@web3-react/core';

const useBridge = () => {
  const { account, library } = useWeb3React();

  //  rinkeby
  const srcChainId = 4;

  // optimism kovan
  const dstChainId = 69;

  // address of the NFT collection on the source chain -> on Rinekby(in this example)
  const nftCollectionAddress = '...';

  // token Id owned by account
  const tokenId = '...';

  //  provider
  let provider;
  // in case of ethers.js
  provider = library.provider;
  // in case of web3.js
  provider = library.currentProvider;
  
  const estimateFee = async () => {
   
    try {
      const estimatedFees = await estimateBridgeFees({
        account,
        dstChainId,
        srcChainId,
        provider,
        tokenId,
        nftSrcContractAddress
      });
      console.log(estimateFee)
    } catch (err) {
      console.error(err);
    }
};

  const bridgeNFT = async () => {
    try {
      const approveTx = await approve(
        srcChainId,
        nftCollectionAddress,
        tokenId,
        provider,
        account
      );

      const bridgeTx = await bridge(
        srcChainId,
        dstChainId,
        nftCollectionAddress,
        tokenId,
        provider,
        account
      );
    } catch (err) {
      console.log(err);
    }
    return { approveTx, bridgeTx };
  };

  return { bridgeNFT };
};