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 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',
networks: [
{
chainId: '42',
currency: {
decimals: 9,
icon: '...',
name: 'Native currency',
symbol: 'EVER',
wrappedCurrencyAddress: new AddressLiteral( '0:a49cd4e158a9a15555e624759e2e4e766d22600b7800d891e46f9291f044a93d'),
},
explorer: {
accountsSubPath: 'accounts',
baseUrl: 'https://everscan.io',
title: 'Everscan',
transactionsSubPath: 'transactions',
},
id: 'tvm-42',
name: 'Everscale',
provider: 'everscale',
rpcUrl: '',
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({
decimals: 18,
symbol: 'ETH',
}, {
networks: [
{
chainId: '1',
currencySymbol: 'ETH',
explorerBaseUrl: 'https://etherscan.io/',
id: 'evm-1',
label: 'Ethereum',
name: 'Ethereum Mainnet',
rpcUrl: 'https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161',
transactionType: '0x2',
type: 'evm',
},
{
chainId: '56',
currencySymbol: 'BNB',
explorerBaseUrl: 'https://bscscan.com/',
id: 'evm-56',
label: 'BNB Chain (Binance Smart Chain)',
name: 'BNB Chain',
rpcUrl: 'https://bsc-dataseed.binance.org/',
transactionType: '0x0',
type: 'evm',
},
],
})
await evmWalletService.connect()
First argument is same as in TvmWalletService - blockchain native currency.
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')
evmWalletService.changeNetwork('1')
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'
const tokensListService = new TokensListService('https://raw.githubusercontent.com/broxus/flatqube-assets/master/manifest.json')
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,
vendor: 'broxus'
})
const userWallet = await token.wallet(ownerAddress: Address | string)