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

@depay/web3-assets-evm

v7.4.1

Published

JavaScript library to retrieve Web3 assets of a given or connected wallet/account.

Downloads

82

Readme

Quickstart

yarn add @depay/web3-assets

or

npm install --save @depay/web3-assets
import { getAssets } from '@depay/web3-assets'

let assets = await getAssets({
  accounts: {
    ethereum: '0x08B277154218CCF3380CAE48d630DA13462E3950',
    bsc: '0x08B277154218CCF3380CAE48d630DA13462E3950' 
  } 
})
//[
// {
//   "name": "Dai Stablecoin",
//   "symbol": "DAI",
//   "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
//   "blockchain": "ethereum",
//   "type": "20",
//   "balance": "8007804249707967889272"
// }, {
//   "name": "DePay",
//   "symbol": "DEPAY",
//   "address": "0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb",
//   "blockchain": "ethereum",
//   "type": "20",
//   "balance": "212816860003097638129"
// }, {
//   "name": "PancakeSwap Token",
//   "symbol": "CAKE",
//   "address": "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82",
//   "blockchain": "bsc",
//   "type": "20",
//   "balance": "2221112213212321"
// }
//]
import { dripAssets } from '@depay/web3-assets'

let allAssets = await dripAssets({
  accounts: { ethereum: '0x08B277154218CCF3380CAE48d630DA13462E3950', bsc: '0x08B277154218CCF3380CAE48d630DA13462E3950' },
  priority: [
    { blockchain: 'ethereum', address: '0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb' },
    { blockchain: 'bsc', address: '0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb' },
    { blockchain: 'ethereum', address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' },
    { blockchain: 'bsc', address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c' }
  ],
  drip: (asset)=>{
    // {
    //   "name": "DePay",
    //   "symbol": "DEPAY",
    //   "address": "0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb",
    //   "blockchain": "ethereum",
    //   "type": "20",
    //   "balance": "212816860003097638129"
    // }
  }
})

Support

This library supports the following blockchains:

Platform specific packaging

In case you want to use and package only specific platforms, use the platform-specific package:

EVM platform specific packaging

import { getAssets } from '@depay/web3-assets-evm'

Solana platform specific packaging

import { getAssets } from '@depay/web3-assets-solana'

Functionalities

getAssets

Retrieves all assets of the given account on the given blockchains:


import { getAssets } from '@depay/web3-assets'

let assets = await getAssets({
  accounts: {
    ethereum: '0x08B277154218CCF3380CAE48d630DA13462E3950',
    bsc: '0x08B277154218CCF3380CAE48d630DA13462E3950'
  }
})
//[
// {
//   "name": "Dai Stablecoin",
//   "symbol": "DAI",
//   "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
//   "blockchain": "ethereum",
//   "type": "20",
//   "balance": "8007804249707967889272"
// }, {
//   "name": "DePay",
//   "symbol": "DEPAY",
//   "address": "0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb",
//   "blockchain": "ethereum",
//   "type": "20",
//   "balance": "212816860003097638129"
// }, {
//   "name": "PancakeSwap Token",
//   "symbol": "CAKE",
//   "address": "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82",
//   "blockchain": "bsc",
//   "type": "20",
//   "balance": "2221112213212321"
// }
//]

Timeout happens after 10s and [] will be returned in cases the assets for the given addresses can't be retrieved within 10s.

only (getAssets)

Only gets assets and balances for given token addresses.


import { getAssets } from '@depay/web3-assets'

let assets = await getAssets({
  accounts: {
    ethereum: '0x08B277154218CCF3380CAE48d630DA13462E3950',
    bsc: '0x08B277154218CCF3380CAE48d630DA13462E3950'
  },
  only: {
    ethereum: ['0x6B175474E89094C44Da98b954EedeAC495271d0F'],
    bsc: ['0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82']
  }
})
//[
// {
//   "name": "Dai Stablecoin",
//   "symbol": "DAI",
//   "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
//   "blockchain": "ethereum",
//   "type": "20",
//   "balance": "8007804249707967889272"
// }, {
//   "name": "PancakeSwap Token",
//   "symbol": "CAKE",
//   "address": "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82",
//   "blockchain": "bsc",
//   "type": "20",
//   "balance": "2221112213212321"
// }
//]

exclude (getAssets)

Excludes given assets


import { getAssets } from '@depay/web3-assets'

let assets = await getAssets({
  accounts: {
    ethereum: '0x08B277154218CCF3380CAE48d630DA13462E3950',
    bsc: '0x08B277154218CCF3380CAE48d630DA13462E3950'
  },
  exclude: {
    ethereum: ['0x6B175474E89094C44Da98b954EedeAC495271d0F'],
    bsc: ['0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82']
  }
})
//[
// {
//   "name": "DePay",
//   "symbol": "DEPAY",
//   "address": "0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb",
//   "blockchain": "ethereum",
//   "type": "20",
//   "balance": "212816860003097638129"
// }
//]

dripAssets

Drips every single asset immediately after resolved and all assets after all assets have been resolved (just as getAssets):

import { dripAssets } from '@depay/web3-assets'

let allAssets = await dripAssets({
  accounts: { ethereum: '0x08B277154218CCF3380CAE48d630DA13462E3950', bsc: '0x08B277154218CCF3380CAE48d630DA13462E3950' },
  priority: [
    { blockchain: 'ethereum', address: '0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb' },
    { blockchain: 'bsc', address: '0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb' },
    { blockchain: 'ethereum', address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' },
    { blockchain: 'bsc', address: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c' },
  ],
  drip: (asset)=>{
    // {
    //   "name": "DePay",
    //   "symbol": "DEPAY",
    //   "address": "0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb",
    //   "blockchain": "ethereum",
    //   "type": "20",
    //   "balance": "212816860003097638129"
    // }
  }
})

only (dripAssets)

Only drips assets and balances for given token addresses.


import { dripAssets } from '@depay/web3-assets'

let assets = await dripAssets({
  accounts: {
    ethereum: '0x08B277154218CCF3380CAE48d630DA13462E3950',
    bsc: '0x08B277154218CCF3380CAE48d630DA13462E3950'
  },
  only: {
    ethereum: ['0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb'],
    bsc: ['0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb']
  },
  drip: (asset)=>{
    // {
    //   "name": "DePay",
    //   "symbol": "DEPAY",
    //   "address": "0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb",
    //   "blockchain": "ethereum",
    //   "type": "20",
    //   "balance": "212816860003097638129"
    // }
  }
})

exclude (dripAssets)

Drips all assets except the ones you "exclude":


import { dripAssets } from '@depay/web3-assets'

let assets = await dripAssets({
  accounts: {
    ethereum: '0x08B277154218CCF3380CAE48d630DA13462E3950',
    bsc: '0x08B277154218CCF3380CAE48d630DA13462E3950'
  },
  exclude: {
    ethereum: ['0x6B175474E89094C44Da98b954EedeAC495271d0F'],
    bsc: ['0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82']
  },
  drip: (asset)=>{
    // {
    //   "name": "DePay",
    //   "symbol": "DEPAY",
    //   "address": "0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb",
    //   "blockchain": "ethereum",
    //   "type": "20",
    //   "balance": "212816860003097638129"
    // }
  }
})

Development

Get started

yarn install
yarn dev

Release

npm publish