项目作者: DePayFi

项目描述 :
⛓ JavaScript library containing abstractions and aggregated information for blockchains.
高级语言: JavaScript
项目地址: git://github.com/DePayFi/depay-blockchains.git
创建时间: 2021-06-21T07:27:09Z
项目社区:https://github.com/DePayFi/depay-blockchains

开源协议:MIT License

下载


Quickstart

  1. yarn add @depay/web3-blockchains

or

  1. npm install --save @depay/web3-blockchains
  1. import Blockchains from '@depay/web3-blockchains'
  2. Blockchains.all
  3. // [
  4. // { name: 'ethereum', id: '0x1', label: 'Ethereum', logo: '...' },
  5. // { name: 'bsc', id: '0x38', label: 'Binance Smart Chain', logo: '...' },
  6. // ...
  7. // ]
  8. Blockchains.findByName('ethereum')
  9. // { name: 'ethereum', id: '0x1', label: 'Ethereum', logo: '...' }
  10. Blockchains.findById('0x1')
  11. // { name: 'ethereum', id: '0x1', label: 'Ethereum', logo: '...' }
  12. Blockchains.findByNetworkId(1)
  13. // { name: 'ethereum', id: '0x1', label: 'Ethereum', logo: '...' }

or

  1. import { all, findByName, findById, findByNetworkId } from '@depay/web3-blockchains'
  2. all
  3. // [
  4. // { name: 'ethereum', id: '0x1', label: 'Ethereum', logo: '...' },
  5. // { name: 'bsc', id: '0x38', label: 'Binance Smart Chain', logo: '...' },
  6. // ...
  7. // ]
  8. findByName('ethereum')
  9. // { name: 'ethereum', id: '0x1', label: 'Ethereum', logo: '...' }
  10. findById('0x1')
  11. // { name: 'ethereum', id: '0x1', label: 'Ethereum', logo: '...' }
  12. findByNetworkId(1)
  13. // { name: 'ethereum', id: '0x1', label: 'Ethereum', logo: '...' }

or

  1. import Blockchains from '@depay/web3-blockchains'
  2. Blockchains['ethereums']
  3. // { name: 'ethereum', id: '0x1', label: 'Ethereum', logo: '...' }

Support

This library supports the following blockchains:

Data Structure

Blockchain data is provided in the following structure:

  1. {
  2. name: String, // e.g. ethereum, bsc ...
  3. id: String, // e.g. 0x1, 0x38, ...
  4. networkId: String, // 1, 56, ...
  5. namespace: String, // eip155, solana, ...
  6. label: String, // Ethereum, Binance Smart Chain ...
  7. fullName: String, // Ethereum Mainnet, Binance Smart Chain Mainnet ...
  8. logo: String, // base64 data or URL (logo for colored or dark background)
  9. logoBackgroundColor: String // hex color
  10. logoWhiteBackground: String // base64 data or url (logos for white background)
  11. currency: { Object
  12. name: String, // Ether, Binance Coin, ...
  13. symbol: String, // ETH, BNB, ...
  14. decimals: String, // 18
  15. address: String, // address or placeholder address
  16. logo: String, // base64 data or URL,
  17. },
  18. wrapped: { Object
  19. address: String, // address of the wrapped native scurrency
  20. decimals: Integer, // 18
  21. logo: String, // base64 data or URL
  22. },
  23. stables: { Object
  24. usd: [ Array
  25. { Object
  26. address: String, // 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
  27. decimals: Integer, // 18
  28. }, ...
  29. ]
  30. },
  31. explorer: String (URL), // https://etherscan.io, https://bncscan.com, ...
  32. explorerUrlFor: Function ({ transaction || token }) returns String, // https://etherscan.io/tx/..., https://etherscan.io/token/...
  33. endpoints: [ Array
  34. String (URL), // https://rpc.ankr.com/eth
  35. ],
  36. sockets: [ // Array || undefined
  37. String (URL), // wss://mainnet-beta.solflare.network
  38. ],
  39. tokens: [ Array
  40. { Object
  41. address: String, // 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
  42. symbol: String, // USDC
  43. name: String, // USD Coin
  44. decimals: Integer, // 6
  45. logo: String(URL|Data URL), // https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x853d955aCEf822Db058eb8505911ED77F175b99e/logo.png
  46. type: String, // 20
  47. },
  48. ],
  49. zero: String, // 0x0000000000000000000000000000000000000000
  50. maxInt: String, // 115792089237316195423570985008687907853269984665640564039457584007913129639935
  51. permit2: String, // 0x000000000022D473030F116dDEE9F6B43aC78BA3 (Permit2 contract address)
  52. blockTime: Integer, // in ms e.g. ethereum 12000 (12s)
  53. }

explorerUrlFor

Transaction

  1. blockchain.explorerUrlFor({ transaction: '0x51ae8875028b7ed004253f679076851abbd3a49e26faf8d7dac6bb283ca10536' })
  2. // https://etherscan.io/tx/0x51ae8875028b7ed004253f679076851abbd3a49e26faf8d7dac6bb283ca10536

Token

  1. blockchain.explorerUrlFor({ token: '0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb' })
  2. // https://etherscan.io/token/0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb

Address

  1. blockchain.explorerUrlFor({ address: '0x08B277154218CCF3380CAE48d630DA13462E3950' })
  2. // https://etherscan.io/address/0x08B277154218CCF3380CAE48d630DA13462E3950

Functionalities

all: Retreive all information for all blockchains

  1. import Blockchains from '@depay/web3-blockchains'
  2. Blockchains.all
  3. // [
  4. // { name: 'ethereum', id: '0x1', networkId: '1', label: 'Ethereum', logo: '...' },
  5. // { name: 'bsc', id: '0x38', networkId: '56', label: 'Binance Smart Chain', logo: '...' },
  6. // ...
  7. // ]

findById: Get blockchain by blockchain id

  1. import Blockchains from '@depay/web3-blockchains'
  2. Blockchains.findById('0x1')
  3. // { name: 'ethereum', id: '0x1', networkId: '1', label: 'Ethereum', logo: '...' }
  4. Blockchains.findById('0x38')
  5. // { name: 'bsc', id: '0x38', networkId: '56', label: 'Binance Smart Chain', logo: '...' }

findByName: Get blockchain by blockchain name

  1. import Blockchains from '@depay/web3-blockchains'
  2. Blockchains.findByName('ethereum')
  3. // { name: 'ethereum', id: '0x1', networkId: '1', label: 'Ethereum', logo: '...' }
  4. Blockchains.findByName('bsc')
  5. // { name: 'bsc', id: '0x38', networkId: '56', label: 'Binance Smart Chain', logo: '...' }

findByNetworkId: Get blockchain by network id

  1. import Blockchains from '@depay/web3-blockchains'
  2. Blockchains.findByNetworkId(1)
  3. // { name: 'ethereum', id: '0x1', networkId: '1', label: 'Ethereum', logo: '...' }
  4. Blockchains.findByNetworkId('56')
  5. // { name: 'bsc', id: '0x38', networkId: '56', label: 'Binance Smart Chain', logo: '...' }

Development

Get started

  1. yarn install
  2. yarn dev