npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kresuslabs/wallet

v0.8.1-alpha.1

Published

Collection of helper and util functions for integrating blockchain functionalities to Kresus mobile app

Downloads

247

Readme

Kresus Wallet SDK

Name

kresus-wallet

Installation

1. Install with npm:

npm i @kresuslabs/wallet

2. Install with yarn:

yarn add @kresuslabs/wallet

Usage For Ethereum

Create Instance of ETHWallet:

import { ETHWallet, Env } from '@kresuslabs/wallet';

/*
  Chain ids Ethereum:
    a.  mainnet - 1
    b.  goerli  - 5
    c.  rinkeby - 4
    d.  ropsten - 3
  
  Chain ids Polygon:
    a. mainnet  - 137
    b. testnet  - 80001

  Chain ids Polygon ZkEVM:
    a. mainnet  - 1101
    b. testnet  - 1442

  Chain ids Arbitrum:
    a. mainnet  - 42161
    b. testnet  - 421613

  Environments:
    a.  Env.dev
    b.  Env.dev_integration
    c.  Env.stg
    d.  Env.uat
    e.  Env.prod
*/
const configEth = {
  chainId : 5,
  env: Env.dev,
  rpcApiKey: "your_rpc_api_key",
  moralisApiKey: "your_moralis_api_key",
  etherscanApiKey: "your_etherscan_api_key",
  blocknativeApiKey: "your_blocknative_api_key",
}

const ethWallet = new ETHWallet(configEth);

Usage For Solana

Create Instance of SolanaWallet:

import { SolanaWallet, Env } from '@kresuslabs/wallet';

/*
  devnet  - 999
  testnet - 998
  mainnet - 997
*/
const configSol = {
  chainId: 999,
  env: Env.dev,
  shyftApiKey: "your_shyft_api_key"
};

const solWallet = new SolanaWallet(configSol);

Usage For Algorand

Create Instance of AlgorandWallet:

import { AlgorandWallet, Env } from '@kresuslabs/wallet';

/*
  testnet - 798
  mainnet - 799
*/
const configAlgo = {
  chainId : 798
};

const algoWallet = new AlgorandWallet(configAlgo);

Usage For Bitcoin

Create Instance of BitcoinWallet

import { BitcoinWallet, Env } from '@kresuslabs/wallet';

/*
  testnet - 888
  mainnet - 889
*/
const configBtc = {
  chainId: 888,
  env: Env.dev,
  blockDaemonApiKey: "your_block_daemon_api_key"
};

const btcWallet = new BitcoinWallet(configBtc);

Creating Providers with Magic Link

import { ethers } from "ethers";
import { Magic } = require("magic-sdk");
import { SolanaExtension } = require("@magic-ext/solana");
const { BitcoinExtension } = require("@magic-ext/bitcoin");

/*
  Ethereum
*/
const magicEth = new Magic("your_magic_api_key", {network: 'goerli'});
await magicEth.auth.loginWithMagicLink({email: "[email protected]"});
const providerEth = new ethers.providers.Web3Provider(magicEth.rpcProvider);
(await magicEth.user.getMetadata()).publicAddress;    //  get public address

/*
  Polygon
*/
const magicMatic = new Magic("your_magic_api_key", {network: {
    chainId: 80001,
    rpcUrl: "RPC_URL_MUMBAI"
}});

await magicMatic.auth.loginWithMagicLink({email: "[email protected]"});
const providerMatic = new ethers.providers.Web3Provider(magicMatic.rpcProvider);
(await magicMatic.user.getMetadata()).publicAddress;  //  get public address

/*
  Polygon ZkEVM
*/
const magicMatic = new Magic("your_magic_api_key", {network: {
    chainId: 1442,
    rpcUrl: "RPC_URL_ZKEVMTESTNET"
}});

await magicMatic.auth.loginWithMagicLink({email: "[email protected]"});
const providerMatic = new ethers.providers.Web3Provider(magicMatic.rpcProvider);
(await magicMatic.user.getMetadata()).publicAddress;  //  get public address

/*
  Arbitrum
*/
const magicMatic = new Magic("your_magic_api_key", {network: {
    chainId: 421613,
    rpcUrl: "RPC_URL_ARBGOERLI"
}});

await magicMatic.auth.loginWithMagicLink({email: "[email protected]"});
const providerMatic = new ethers.providers.Web3Provider(magicMatic.rpcProvider);
(await magicMatic.user.getMetadata()).publicAddress;  //  get public address

/*
  Solana
*/
const magicInstanceSol = new Magic("your_magic_api_key", {
  extensions: [
    new SolanaExtension({
      rpcUrl: "RPC_URL_FOR_SOLANA",
    }),
  ],
});

/*
  RPC URLs for Solana-
    a.  devnet:         https://api.devnet.solana.com
    b.  testnet:        https://api.testnet.solana.com
    c.  mainnet-beta:   https://api.mainnet-beta.solana.com
*/

await magicInstanceSol.auth.loginWithMagicLink({email: "[email protected]"});
(await magicInstanceSol.user.getMetadata()).publicAddress;    //  get public address

/*
  Bitcoin
*/
const magicInstanceBtc = new Magic("your_magic_api_key", {
  extensions: [
    new BitcoinExtension({
      rpcUrl: "",   //  BTC_RPC_URL or empty string
      network: 'testnet' // testnet or mainnet
      }),
  ],
});

await magicInstanceBtc.auth.loginWithMagicLink({email: "[email protected]"});
(await magicInstanceBtc.user.getMetadata()).publicAddress;    //  get public address

Ethereum Wallet Operations

Get ETH Balance:

const accountAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
await ethWallet.balanceOfETH(providerEth, accountAddr);

Transfer Ethers:

const receiverAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const amount = "0.01";
const pricePerGas = "79816825150";   // in wei
await ethWallet.transferEth(receiverAddr, amount, providerEth, pricePerGas);

Get ERC20 Balance:

const accountAddr = "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5";
const contractAddress  = "0xb5B0cDBf3b42DDEBfaA1Fe95A79d29854F325eD3";
await ethWallet.balanceOfERC20(providerEth, accountAddr, contractAddress);

Transfer ERC20:

const toAddr = "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5";
const amount = "1999999999999999999";
const contractAddress = "0xb5B0cDBf3b42DDEBfaA1Fe95A79d29854F325eD3";
const gasPrice = "79816825150"    //  in wei
await ethWallet.transferERC20(toAddr, amount, contractAddress, gasPrice, providerEth);

Get ERC721 Balance:

const accountAddr = "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5";
const contractAddress = "0xaD8A70DF656f38410640F7102C724Cbf8cC4b932";
await ethWallet.balanceOfERC721(providerEth, accountAddr, contractAddress);

Transfer ERC721:

const fromAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const toAddr = "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5";
const tokenId = "1";
const contractAddress = "0xaD8A70DF656f38410640F7102C724Cbf8cC4b932";
const pricePerGas = "200000000000";   // in wei
await ethWallet.transferERC721(fromAddr, toAddr, tokenId, contractAddress, pricePerGas, providerEth);

Get ERC1155 Balance:

const userAddress = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const tokenId = "1";
const contractAddress = "0xaD8A70DF656f38410640F7102C724Cbf8cC4b932";
await ethWallet.getERC1155Balance(userAddress, tokenId, contractAddress, providerEth);

Transfer ERC1155:

const fromAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const toAddr = "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5";
const tokenId = "1";
const amount = "1";
const data = "0x";
const contractAddress = "0xaD8A70DF656f38410640F7102C724Cbf8cC4b932";
const pricePerGas = "200000000000";
await ethWallet.transferERC1155(fromAddr, toAddr, tokenId, amount, data, contractAddress, pricePerGas, providerEth);

Transfer Multiple ERC1155

const fromAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const toAddr = "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5";
const tokenIdsArr = ["12", "121"];
const amountsArr = ["2", "3"];
const data = "0x";
const contractAddress = "0xaD8A70DF656f38410640F7102C724Cbf8cC4b932";
await ethWallet.batchTransferERC1155(fromAddr, toAddr, tokenIdsArr, amountsArr, data, contractAddress, providerEth);

Get Balances of Multiple ERC1155 Tokens:

const accountsArr = ["0x42681cC5478a619e36a85ddCF583DC750a690ed1", "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5"];
const tokenIdsArr = ["1", "2"];
const contractAddress = "0xaD8A70DF656f38410640F7102C724Cbf8cC4b932";
await ethWallet.getBalanceOfBatch(accountsArr, tokenIdsArr, contractAddress, providerEth);

Set Approval for All ERC1155:

const operatorAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const approved = true;
const contractAddress = "0xaD8A70DF656f38410640F7102C724Cbf8cC4b932";
await ethWallet.setApprovalForAll(operatorAddr, approved, contractAddress, providerEth);

Get Token URI:

const tokenId = "1";
const contractAddress = "0xaD8A70DF656f38410640F7102C724Cbf8cC4b932";
await ethWallet.getERC1155TokenData(providerEth, tokenId, contractAddress);

Get NFTs:

const ownerAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const chain = "goerli"
await ethWallet.getNFTs(ownerAddr, chain);

Get ERC20 Tokens:

const ownerAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const chain = "goerli";
await ethWallet.getERC20(ownerAddr, chain);

Get Transaction History:

const accountAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
await ethWallet.getTransfers(accountAddr);    // get the token details from raw contract object

Get Gas Estimate for Contract Interactions (Alchemy):

const contractAddress = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const functionName = "store";
const params = ["100"];
const amountInEth = undefined;    // defined in string when needed for payable functions
await ethWallet.gasEstimateForContractInteractions(contractAddress, providerEth, contractAbi, functionName, amountInEth, ...params);

Get Gas Estimate for Native Crypto Transfer (Alchemy):

const toAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const amountInEth = "0.1";
await ethWallet.nativeTransferEstimate(providerEth, amountInEth, toAddr);

Get Gas Estimates with Speeds for Contract Interactions (Blocknative):

const contractAddress = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const functionName = "store";
const params = ["100"];
const amountInEth = undefined;    // defined in string when needed for payable functions
await ethWallet.getGasEstimatesForContractInteractions(contractAddress, providerEth, contractAbi, functionName, amountInEth, ...params);

Get Gas Estimates with Speeds for Native Crypto Transfer (Blocknative):

const toAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const amountInEth = "0.1";
await ethWallet.getGasEstimatesForNative(providerEth, amountInEth, toAddr);

Get Txn Receipt:

const txnHash = "0x30e74831aec9d63ee9b38f772e7c5d79be040d81e8196b30cba4bb7cfffd2ac5";
const chainId = 5;    //  goerli
const chain = "eth"   //  "poly" for polygon
const authToken = "AUTHENTICATION_TOKEN";
const orgId = "ORGANIZATION_ID";    //  example: "Kresus"
await ethWallet.getTxnReceipt(txnHash, chainId, chain, authToken, orgId);

Get Txn Details for Pending:

const chain = "eth"   //  "poly" for polygon
const txnHash = "0x30e74831aec9d63ee9b38f772e7c5d79be040d81e8196b30cba4bb7cfffd2ac5";
const authToken = "AUTHENTICATION_TOKEN";
const orgId = "ORGANIZATION_ID";    //  example: "Kresus"
await ethWallet.getTxnPending(chain, txnHash, providerEth, authToken, orgId);

Speedup Transaction:

const txnHash = "0xa86d46fa8e436bdcaf3dcd3820240ecb2d0f945bbc92d23accb6ec9a9e355d22";  // hash of the pending transaction
const gasPrice = "8787651325";    //  in wei
const maxFeePerGas = "948747373";   //  in wei or undefined for legacy type transactions
const maxPriorityFeePerGas = "567899";    //  in wei or undefined for legacy type transactions
await ethWallet.speedupTxn(providerEth, txnHash, gasPrice, maxFeePerGas, maxPriorityFeePerGas);

Retry Transaction:

const txnHash = "0xa86d46fa8e436bdcaf3dcd3820240ecb2d0f945bbc92d23accb6ec9a9e355d22";  // hash of the failed transaction
const gasPrice = "8787651325";    //  in wei
const maxFeePerGas = "948747373";   //  in wei or undefined for legacy type transactions
const maxPriorityFeePerGas = "567899";    //  in wei or undefined for legacy type transactions
await ethWallet.retryTxn(providerEth, txnHash, gasPrice, maxFeePerGas, maxPriorityFeePerGas)

Cancel Transaction:

const txnHash = "0xa86d46fa8e436bdcaf3dcd3820240ecb2d0f945bbc92d23accb6ec9a9e355d22";  // hash of the pending transaction
const gasPrice = "8787651325";    //  in wei
const maxFeePerGas = "948747373";   //  in wei or undefined for legacy type transactions
const maxPriorityFeePerGas = "567899";    //  in wei or undefined for legacy type transactions
await ethWallet.cancelTxn(providerEth, txnHash, gasPrice, maxFeePerGas, maxPriorityFeePerGas);

Call Contract Function:

const contractAddress = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const functionName = "transfer";
const params = ["0xa6D1741395Fe9378630931A2775F0Cea595F46E6", "0.01"];
await ethWallet.callContractFunction(providerEth, contractAddress, contractAbi, functionName, ...params);

Solana Wallet Operations

Validate Solana Address (Public Key):

const accountAddress = "AFRgYC29sBjMGVEaxPNwYk9YPxrZLgCRrE3FRPLKdYAG";
await solWallet.isValidSolanaAddress(accountAddress);

Generate a new Key-pair:

const account = await solWallet.generateAccount();
const accountAddress = account.publicKey.toBase58();

Get SOL from Testnet or Devnet Faucet:

const receiverAddress = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
await solWallet.requestSOL(receiverAddress);

Get Balance of SOL:

const accountAddress = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
await solWallet.balanceOfSOL(accountAddress);

Transfer SOL:

const senderAddr = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
const receiverAddr = "21XJiJCTyu8gg4mxyGRmadBoDrHQyrNEFZ5pUUx5Bb7W";
const amount = 1;   // amount in SOL
await solWallet.transferSOL(senderAddr, receiverAddr, amount, magicInstanceSol);

Fetch SPL Token Balance and Details:

const accountAddress = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
const tokenMintAddress = "5ZbZri5jgPPMmnWq9yDyBG4pK7snPE4id6JPPeQfuQ1K";
await solWallet.getUserTokenBalanceAndDetails(accountAddress, tokenMintAddress);

Fetch Token Account Address:

const accountAddress = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
const tokenMintAddress = "5ZbZri5jgPPMmnWq9yDyBG4pK7snPE4id6JPPeQfuQ1K";
await solWallet.getTokenAccount(accountAddress, tokenMintAddress);

Initialize Token Account Address:

const accountAddress = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
const tokenMintAddress = "5ZbZri5jgPPMmnWq9yDyBG4pK7snPE4id6JPPeQfuQ1K";
await solWallet.setupTokenAccount(tokenMintAddress, accountAddress, magicInstanceSol);

Fetch All User's SPL Token Info:

const accountAddress = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
await solWallet.getAllUserSPLTokens(accountAddress);

Fetch All User's Solana NFT Collection(s):

const accountAddress = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
await solWallet.getAllUserNftCollections(accountAddress);

Get Token Information for Solana (SPL/NFT):

const tokenAddress = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
await solWallet.getTokenInfoSolana(tokenAddress);

Get Token Metadata for Solana:

const tokenAddress = "6FziSMvRXrXUYmeViyEyy1WGz2gU3879mZxLjwKPJQP";
await solWallet.getTokenMetadataSolana(tokenAddress);

Transfer SPL tokens:

const senderAddr = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
const receiverAddr = "21XJiJCTyu8gg4mxyGRmadBoDrHQyrNEFZ5pUUx5Bb7W";
const tokenMintAddress = "5ZbZri5jgPPMmnWq9yDyBG4pK7snPE4id6JPPeQfuQ1K";
const amount = 1;
await solWallet.transferSPLTokens(tokenMintAddress, senderAddr, receiverAddr, amount, magicInstanceSol);

Transfer Solana NFT:

const senderAddr = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
const receiverAddr = "21XJiJCTyu8gg4mxyGRmadBoDrHQyrNEFZ5pUUx5Bb7W";
const tokenMintAddress = "6FaYri5jgPPMmnWq9yDyBG4pK7snPE4id6JPPeQfuP1Q";
await solWallet.transferSolanaNFT(tokenMintAddress, senderAddr, receiverAddr, magicInstanceSol);

Fetch All User's Transfer Transactions:

const accountAddress = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
await solWallet.getAllTransferTransactions(accountAddress);

Fetch All User's SOL Transfer Transactions:

const accountAddress = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
await solWallet.getSolTransferTxns(accountAddress);

Fetch All User's SPL Token Transfer Transactions:

const accountAddress = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
await solWallet.getSplTokenTransferTxns(accountAddress);

Get Txn Receipt for Signature:

const signature = "341AXYH29Qr3sQh6gRFm1Yh9u8o8TrXJ74iGNMJVKPwFHLvibfk2iX8ZzHcHNXy6cD5q5FhutM35bZzQt3S4MVPd";
const authToken = "AUTHENTICATION_TOKEN";
const orgId = "ORGANIZATION_ID";    //  example: "Kresus"
await solWallet.getTxnReceiptSOL(signature, authToken, orgId);

Get Txn Status with Details for a Signature:

const signature = "341AXYH29Qr3sQh6gRFm1Yh9u8o8TrXJ74iGNMJVKPwFHLvibfk2iX8ZzHcHNXy6cD5q5FhutM35bZzQt3S4MVPd";
await solWallet.getSolTxnStatus(signature);

Bitcoin Wallet Operations

Get Balance of Bitcoin (BTC):

const accountAddress = "muHd7wv1rdbzKEQ6ymMHb1FxzRk9SKVeXd";
await btcWallet.balanceOfBTC(accountAddress);

Get Maximum Bitcoin (BTC) Transferable:

const accountAddress = "muHd7wv1rdbzKEQ6ymMHb1FxzRk9SKVeXd";
await btcWallet.maxBitcoinTransferable(accountAddress);

Transfer Bitcoin (BTC):

const senderAddr = "n3t3dJeRGGj4TwjjHd852uvG446PuZ4RTY";
const receiverAddr = "muHd7wv1rdbzKEQ6ymMHb1FxzRk9SKVeXd";
amount = 0.001;   //  in BTC 
txnFees = 2000;   //  in Satoshi. 1 BTC = 100000000 Satoshi
await btcWallet.transferBitcoin(senderAddr, receiverAddr, amount, txnFees, magicInstanceBtc);

Transfer Bitcoin (BTC) - V2

const senderAddr = "n3t3dJeRGGj4TwjjHd852uvG446PuZ4RTY";
const receiverAddr = "muHd7wv1rdbzKEQ6ymMHb1FxzRk9SKVeXd";
amount = 0.001;   //  in BTC 
txnFees = 2000;   //  in Satoshi. 1 BTC = 100000000 Satoshi
await btcWallet.transferBitcoinV2(senderAddr, receiverAddr, amount, txnFees, magicInstanceBtc);

Get Fee Estimate for a Transaction:

await btcWallet.getFeeEstimateForTxn();

Get Fee Estimate for a Transaction - V2:

const accountAddr = "n3t3dJeRGGj4TwjjHd852uvG446PuZ4RTY";
await btcWallet.getFeeEstimateForTxnV2(accountAddr);

Validate Bitcoin Address:

const accountAddr = "n3t3dJeRGGj4TwjjHd852uvG446PuZ4RTY";
await btcWallet.isValidBitcoinAddress(accountAddr);

Get Txn Receipt for Bitcoin (BTC):

const txnHash = "578e635a7cb97034bddcf0a8329e33885c90e1dd4598875ede6b9dcf73815630";
const authToken = "AUTHENTICATION_TOKEN";
const orgId = "ORGANIZATION_ID";    //  example: "Kresus"
await btcWallet.getTxnReceiptBitcoin(txnHash, authToken, orgId);

Get Top 10 Unspent Transaction Outputs by Value:

const btcAddress = "n3t3dJeRGGj4TwjjHd852uvG446PuZ4RTY";
await btcWallet.getTopUnspentTxnOutputs(btcAddress);

Get All Unspent Transaction Outputs:

const btcAddress = "n3t3dJeRGGj4TwjjHd852uvG446PuZ4RTY";
await btcWallet.getAllUnspentTxnOutputs(btcAddress);

Algorand Wallet Operations

Generate a new Algorand Account:

await algoWallet.generateAccount();

Get Balance of ALGO:

const address = "LQM6TANF5LDLKOCQMVUR7SBUUPBC77LDV9Z7XM76RXALFETPHBQWFF6LBE";
await algoWallet.balanceOfALGO(address);

Transfer ALGO:

// should be your own magic link account
const sender = "LQM6TANF5LDLKOCQMVUR7SBUUPBC77LDV9Z7XM76RXALFETPHBQWFF6LBE";
const receiver = "T2RGETP5BEY3RTMJOHXNPKR6QHLCCYGLJLXYT2WER2J22QYFM3DSAI43UQ";
let amount = 2;   // amount in ALGO
await algoWallet.transferALGO(sender, receiver, amount, magicInstanceAlgo);

Get Algorand Standard Asset (ASA) Balance:

const userAddr = "LQM6TANF5LDLKOCQMVUR7SBUUPBC77LDV9Z7XM76RXALFETPHBQWFF6LBE";
const tokenIndex = 79404320;  // Asset Id
await algoWallet.getUserASABalance(userAddr, tokenIndex);

Get Details of Algorand Standard Asset (ASA):

const tokenIndex = 79404320;  // Asset Id
await algoWallet.getASADetails(tokenIndex);

Opt-In to Algorand Standard Asset (ASA):

// should be your own magic link account
const userAddr = "LQM6TANF5LDLKOCQMVUR7SBUUPBC77LDV9Z7XM76RXALFETPHBQWFF6LBE";
const tokenIndex = 79404320;
await algoWallet.optIntoToken(userAddr, tokenIndex, magicInstanceAlgo);

Transfer Algorand Standard Asset (ASA):

// should be your own magic link account
const senderAddr = "LQM6TANF5LDLKOCQMVUR7SBUUPBC77LDV9Z7XM76RXALFETPHBQWFF6LBE";
const receiverAddr = "Q2RGETP5BEY3RTMJOHXNPKR6QHFCCYGLJLXYT2WER2J22QYFM3DSAI43UQ";
const tokenIndex = 79404320;  // Asset Id
const amount = 100;
await algoWallet.transferASA(senderAddr, receiverAddr, tokenIndex, amount, magicInstanceAlgo);

Fetch All ALGO Transfer Transactions:

let address = "LQM6TANF5LDLKOCQMVUR7SBUUPBC77LDV9Z7XM76RXALFETPHBQWFF6LBE";
await algoWallet.getALGOTransfers(address);

Fetch All Algorand Standard Asset (ASA) Transfer Transactions:

let address = "LQM6TANF5LDLKOCQMVUR7SBUUPBC77LDV9Z7XM76RXALFETPHBQWFF6LBE";
await algoWallet.getASATransfers(address);

Usage for Pinata

Create Instance of IPFS:

import {IpfsApi} from "@kresuslabs/wallet";

const config = {
  apiKey: "your_api_key",
  secretApiKey: "your_secret_api_key"
}

const ipfsClient = new IpfsApi(config);

Upload and Pin File to IPFS:

const file = event.target.files[0];
const fileName = "some_file_name";
await ipfsClient.uploadFileToIPFS(file, fileName);

Upload and Pin File to IPFS from React Native:

await ipfsClient.uploadFileReactNative(formData, customHeaders);

Upload and Pin File with Category to IPFS:

const file = event.target.files[0];
const fileCategory = "custom-file-category";
await ipfsClient.uploadFileWithCategoryToIPFS(file, fileCategory );

Upload and Pin JSON Data (not file) to IPFS:

const jsonData = {
  pinataMetadata: {
    name: "my-custom-name"
  },
  pinataContent: {
    message: "Hey there! I am some-json-content"
  }
};
await ipfsClient.uploadJsonToIPFS(jsonData);

Retrieve Pinned Content from IPFS:

const cid = "QmWBiLYnDbKNpJpyngyPwD12CsaHRad3abdDVVcw3VYHLX";
await ipfsClient.retrieveContentFromIPFS(cid);

Usage for Utils

Create Instance of Utils

import { Utils, Env, AssetPlatformCoinGecko } from '@kresuslabs/wallet';

/*
  Environments:
    a.  Env.dev
    b.  Env.dev_integration
    c.  Env.stg
    d.  Env.uat
    e.  Env.prod
*/
const configUtils = {
  coingeckoApiKey: "api_key_for_coingecko",
  env: Env.dev
}

const utilObj = new Utils(configUtils);

Check validity for an ethereum address:

/*
  isAddress() is a static function. Use class name itself to call the function.
*/
const address = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
Utils.isAddress(address);

Get Exchange Rates in USD:

const ids = ["algorand", "ethereum", "solana"];
await utilObj.getPrices(ids);

Get Exchange Rate in USD for Specific Date:

const id = "algorand";
const dateStr = "30-12-2022";   //  dd-mm-yyyy format
await utilObj.getHistoryPrice(id, dateStr);

Get Price and Market Cap of Tokens in USD by Token Symbols:

const symbols = ["btc","eth","usdt"]; 
await utilObj.getTokensPrice(symbols);

Get Price and Market Cap of Tokens in USD by Token Symbols or Contract Address:

/*
  symbol and chain_name are mandatory parameters
*/
const tokens = [
  {
    symbol: "USDC", // case-insensitive
    contract_addr: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
    chain_name: AssetPlatformCoinGecko.ethereum
  },
  {
    symbol: "XALGO",
    contract_addr: "",  // optional parameter
    chain_name: AssetPlatformCoinGecko.solana
  },
];
await utilObj.getTokensPriceWithContractOrSymbol(tokens);

Get All Assets:

const ethAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const polygonAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const solAddr = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
const btcAddr = "n3t3dJeRGGj4TwjjHd852uvG446PuZ4RTY";
const authToken = "AUTHENTICATION_TOKEN";
const orgId = "ORGANIZATION_ID";    //  example: "Kresus"
await utilObj.getAllAssets(ethAddr, polygonAddr, solAddr, btcAddr, authToken, orgId);

This method is deprecated, use Get NFT Holdings instead

Get All NFTs:

const ethAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const polygonAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const solAddr = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
const authToken = "AUTHENTICATION_TOKEN";
const orgId = "ORGANIZATION_ID";    //  example: "Kresus"
await utilObj.getAllNFTs(ethAddr, polygonAddr, solAddr, authToken, orgId);

Get NFT Holdings:

const ethAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const polygonAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const solAddr = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
const authToken = "AUTHENTICATION_TOKEN";
const orgId = "ORGANIZATION_ID";    // example: "Kresus"
const arbAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1"; // optional parameter
const recCount = 50; // optional parameter
await utilObj.getNFTHoldings(ethAddr, polygonAddr, solAddr, authToken, orgId, arbAddr, recCount);

Get Txn History:

const authToken = "AUTHENTICATION_TOKEN";
const orgId = "ORGANIZATION_ID";    //  example: "Kresus"
const ethAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const polygonAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const solAddr = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
const btcAddr = "n3t3dJeRGGj4TwjjHd852uvG446PuZ4RTY";
const recordCount = 10;   //  optional
await Utils.getTxnHistory(authToken, orgId, ethAddr, polygonAddr, solAddr, btcAddr, recordCount);

Get Funds from Faucet Api:

const ethAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const polygonAddr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const solAddr = "7YgvaQthiN5UGvrFhbz2dp12wcyXosSjGL4C9rHr3E8m";
const authToken = "AUTHENTICATION_TOKEN";
const orgId = "ORGANIZATION_ID";    //  example: "Kresus"
await utilObj.getFunds(ethAddr, polyAddr, solAddr, authToken, orgId);

Usage for Transaction Processor

Create Instance of TxnProcessor

import { TxnProcessor, Env } from '@kresuslabs/wallet';

/*
  Environments:
    a.  Env.dev
    b.  Env.dev_integration
    c.  Env.stg
    d.  Env.uat
    e.  Env.prod
*/
const configTxnProcessor = {
  env: Env.dev
}

const processor = new TxnProcessor(configTxnProcessor);

Add new Txn:

const authToken = "AUTHENTICATION_TOKEN";
const orgId = "ORGANIZATION_ID";    //  example: "Kresus"
const chain = "eth";
const txnHash = "0x27734da29056f8604bf80891fffb62d76734643fcd31ccf53449b7b407a456";
const address = "0x757e2AD0a5729138F7922C9fd1CC2efc92Eb5121";
const txnType = TxnType.native_token_tx,
const receiver = "0x03b22d7742fA2A8a8f01b64F40F0F2185E965cB8";
const userId = "user_unique_Id";
const amount = "1000";
const contractAddress = "0x63c5C1D92EcaFa3bEF9C4B692Dc9A985a70E730f"
const tokenId = "11"
const dataObject = "0xa4c85cca000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000000200000000000000000000000033df7cb11599ee6b589d92f64e12a142c1f452980000000000000000000000000f6c7395e37fe0644b4760cccc1bcd560a44cc7a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000009736f6d656874696e6700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
const status = "confirmed";
await processor.addNewTx(authToken, orgId, chain, txnHash, address, txnType, receiver, userId, tokenAmount, contractAddress, tokenId, dataObject, status);

License

MIT