Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@broxus/js-core

Package Overview
Dependencies
Maintainers
5
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@broxus/js-core

MobX-based JavaScript Core library

  • 0.4.3
  • npm
  • Socket score

Version published
Weekly downloads
80
decreased by-78.84%
Maintainers
5
Weekly downloads
 
Created
Source

Broxus JavaScript Core

Introduction

This library provides MobX-based services, models and helpers to build JavaScript Applications with any popular frameworks or libraries (e.g. React, Angular, Vue, etc.)

Services

Collection of the services to manage states of the wallets connections - TVM-compatible Wallets (e.g. EVER Wallet), EVM-compatible Wallets (e.g. MetaMask), Solana-compatible Wallets (e.g. Phantom). Services to manage tokens list, DEX Account service, etc.

TvmWalletService

Service to connect to a TVM-compatible Wallet like EVER Wallet or Venom Wallet. It has connect and disconnect methods for manually connect and disconnect to the wallet.

import { TvmWalletService } from '@broxus/js-core'

const tvmWalletService = new TvmWalletService({
    defaultNetworkId: 42,
    minWalletVersion: '2.31.0', // min version that suppurts delayed messages sending
    networks: [
        {
            chainId: '42',
            currency: {
                decimals: 9,
                icon: '...',
                name: 'Native currency',
                symbol: 'EVER',
                wrappedCurrencyAddress: new AddressLiteral( '0:a49cd4e158a9a15555e624759e2e4e766d22600b7800d891e46f9291f044a93d'), // WEVER
            },
            explorer: {
                accountsSubPath: 'accounts',
                baseUrl: 'https://everscan.io',
                title: 'Everscan',
                transactionsSubPath: 'transactions',
            },
            id: 'tvm-42',
            name: 'Everscale',
            rpcUrl: 'https://jrpc.everwallet.net/rpc',
            shortName: 'Everscale',
            type: 'tvm',
        },
    ],
    providerId: 'everscale'
})

await tvmWalletService.connect()

For add a custom token asset to the wallet extension tokens assets use method addAsset.

await tvmWalletService.addAsset('0:a49cd4e158a9a15555e624759e2e4e766d22600b7800d891e46f9291f044a93d', 'tip3_token')

DexAccountService

Service to connect to DEX account or create new one. Sync all related token wallets and their balances.

import { DexAccountService } from '@broxus/js-core'

const service = new DexAccountService(everWalletService, {
    dexRoot: new AddressLiteral('0:5eb5713ea9b4a0f3a13bc91b282cde809636eb1e68d2fcb6427b9ad78a5a9008'),
})

First (required) argument is TvmWalletService.

Second one (required) - options, where dexRoot is DEX root address.

EvmWalletService

Service to connect EVM-compatible wallet.

import { EvmWalletService } from '@broxus/js-core'

const evmWalletService = new EvmWalletService({
    networks: [
        {
            chainId: '1',
            currency: {
                decimals: 18,
                icon: 'https://etherscan.io/images/svg/brands/ethereum-original.svg',
                name: 'Native currency',
                symbol: 'ETH',
                wrappedCurrencyAddress: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
            },
            explorer: {
                accountsSubPath: 'address',
                baseUrl: 'https://etherscan.io',
                title: 'Etherscan',
                transactionsSubPath: 'tx',
            },
            id: 'evm-1',
            name: 'Ethereum Mainnet',
            rpcUrl: `https://mainnet.infura.io/v3/${infuraId}`,
            shortName: 'Ethereum',
            transactionType: '0x2',
            type: 'evm',
        },
        {
            chainId: '56',
            currency: {
                decimals: 18,
                icon: 'https://bscscan.com/images/svg/brands/bnb-1.svg?v=1.3',
                name: 'Native currency',
                symbol: 'BNB',
                wrappedCurrencyAddress: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
            },
            explorer: {
                accountsSubPath: 'address',
                baseUrl: 'https://bscscan.com',
                title: 'BscScan',
                transactionsSubPath: 'tx',
            },
            id: 'evm-56',
            name: 'Binance Smart Chain',
            rpcUrl: 'https://rpc.ankr.com/bsc/',
            shortName: 'BSC',
            transactionType: '0x0',
            type: 'evm',
        },
    ],
})

await evmWalletService.connect()

In the second argument you can pass provider options of Web3Modal in modalOptions. Also, you can pass list of available networks.

Through service, you can add or change network in the connected wallet. Use methods addNetwork and changeNetwork

evmWalletService.addNetwork('56') // add BNB network to the wallet networks list
evmWalletService.changeNetwork('1') // change network to Ethereum Mainnet

When you add network with some chainId - this network config should be described in the networks option

TokensListService

Service for load and manage list of the Everscale tokens.

import { TokensListService } from '@broxus/js-core'
import { ProviderRpcClient } from 'everscale-inpage-provider'

const tokensListService = new TokensListService(
    'https://raw.githubusercontent.com/broxus/flatqube-assets/master/manifest.json',
    connection: ProviderRpcClient
)

await tokensListService.init()

Models

TvmToken

Model for the TVM-based token

import { TvmToken } from '@broxus/js-core'

const token = new TvmToken({
    name: 'Wrapped EVER',
    symbol: 'WEVER',
    decimals: 9,
    address: '0:a49cd4e158a9a15555e624759e2e4e766d22600b7800d891e46f9291f044a93d',
    logoURI: 'https://raw.githubusercontent.com/broxus/flatqube-assets/master/icons/WEVER/logo.svg',
    version: 5,
    verified: true,
})

const userWallet = await token.wallet(ownerAddress: Address | string)

Keywords

FAQs

Package last updated on 30 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc