wallets-wrapper
TypeScript icon, indicating that this package has built-in type declarations

0.0.35 • Public • Published

README

How to install

yarn add wallets-wrappers
npm i wallets-wrappers

Example flow

const metamask = new WalletsWrapper({
  type: WalletsNames.Metamask,
  infuraApiKey: process.env.REACT_APP_INFURA_API_KEY || '',
})

metamask
  .init({
    appUrl: 'example.com',
    email: 'example@gmail.com',
  })
  .then(() => {
    metamask.address$.subscribe(setAddress)
    metamask.errors$.subscribe(setError)
    metamask.isConnected$.subscribe(setIsConnected)
    metamask.chainId$.subscribe(setChain)

    metamask.getAddress().then(setAddress)

    metamask.getStandardContract(coinAddresses[CoinNames.USDT]).then(async (contract) => {
      await contract.init()
      const usdtBalance = await contract.getBalance()
    })

    metamask.getStandardContract(ERC20address).then(async (contract) => {
      await contract.init()
      const balance = await contract.getBalance()
      setBalanceERC20(balance)
      setERC20Contract(contract)
    })
    metamask.getStandardContract(ERC721address).then(async (contract) => {
      await contract.init()
      const balance = await contract.getBalance()
      setBalanceERC721(balance)
      setERC721Contract(contract)
    })
    metamask.getStandardContract(ERC1155address).then(async (contract) => {
      await contract.init()
      const balance = await contract.getBalance({ ids: [0, 1] })
      setBalanceERC1155(balance)
      contract
      setERC1155Contract(contract)
    })
  })
  .catch()

const handleClickGetmetamaskwallet = async () => {
  await metamask.connectWallet()
}

const handleClickSwitchmetamasknetwork = async () => {
  await metamask.switchNetwork(ChainIds.GoerliTestNetwork)
}

const handleClickPersonalSign = async () => {
  await metamask.sign({ message: 'Hello signer!', type: 'personal_sign' })
}

const handleClickSendETH = async () => {
  await metamask.transfer({
    addressTo,
    value,
  })
}

const handleClickGetContract = async () => {
  const contract = await metamask.getStandardContract(ERC20ContractAddress?.value || '')
  await contract.init()
}

const handleClickTransferERC20 = async () => {
  await ERC20Contract?.transfer({
    addressTo: addressToERC20?.value || '',
    values: [Number(valueERC20?.value || '')],
  })
}

const handleClickTransferERC721 = async () => {
  await ERC721Contract?.transfer({
    addressTo: addressToERC721?.value || '',
    tokenIds: [Number(tokenIdERC721?.value || '')],
  })
}

const handleClickTransferERC1155 = async () => {
  await ERC1155Contract?.transfer({
    addressTo: addressToERC1155?.value || '',
    tokenIds: [Number(tokenIdERC1155?.value || '')],
    values: [1],
  })
}

const handleClickWatchAsset = async () => {
  await metamask.addToken(CoinNames.USDT)
}

Classes

ERC1155

The client describes how to work with ERC20, ERC721, ERC1155 contracts .

ERC20

The client describes how to work with ERC20, ERC721, ERC1155 contracts .

ERC721

The client describes how to work with ERC20, ERC721, ERC1155 contracts .

StandardContract

The client describes how to work with ERC20, ERC721, ERC1155 contracts .

AnchorWrapper

The client describes how to work with Anchor.

MetamaskWrapper

The client describes how to work with Metamask Extension.

TrezorWrapper

The client describes how to work with Trezor.

WalletsWrapper

The client describes how to work with all wallets. All connection to wallets must be with this client

ERC1155

The client describes how to work with ERC20, ERC721, ERC1155 contracts .

Kind: global class
Implements: IStandardContract

erC1155.init()

Gives access to contract methods, if you don't call init client just won't know which contract to use

Kind: instance method of ERC1155

erC1155.getBalance(object,) ⇒ Promise.<number>

Check balance in contract

Kind: instance method of ERC1155

Param Type
object, GetContractBalance

erC1155.transfer(args) ⇒ Promise.<Transaction>

Transfer token

Kind: instance method of ERC1155

Param Type
args TransferContractToken

erC1155.getDecodedTransfer(args) ⇒ string

get decoded Transfer

Kind: instance method of ERC1155

Param Type
args TransferContractToken

erC1155.getTokenUri(tokenId) ⇒ Promise.<string>

Get token uri, only works when this.type === 'ERC721'

Kind: instance method of ERC1155

Param Type
tokenId string

erC1155.transferEvents()

Subscribe on transfer events in contract

Kind: instance method of ERC1155

ERC20

The client describes how to work with ERC20, ERC721, ERC1155 contracts .

Kind: global class
Implements: IStandardContract

erC20.init()

Gives access to contract methods, if you don't call init client just won't know which contract to use

Kind: instance method of ERC20

erC20.getBalance(object,) ⇒ Promise.<number>

Check balance in contract

Kind: instance method of ERC20

Param Type
object, GetContractBalance

erC20.transfer(args) ⇒ Promise.<Transaction>

Transfer token

Kind: instance method of ERC20

Param Type
args TransferContractToken

erC20.getDecodedTransfer(args) ⇒ string

get decoded Transfer

Kind: instance method of ERC20

Param Type
args TransferContractToken

erC20.transferEvents()

Subscribe on transfer events in contract

Kind: instance method of ERC20

ERC721

The client describes how to work with ERC20, ERC721, ERC1155 contracts .

Kind: global class
Implements: IStandardContract

erC721.init()

Gives access to contract methods, if you don't call init client just won't know which contract to use

Kind: instance method of ERC721

erC721.getBalance(address,, object,) ⇒ Promise.<number>

Check balance in contract

Kind: instance method of ERC721

Param Type Description
address, string

you can specify explicitly to check a different address

object, GetContractBalance

erC721.transfer(args) ⇒ Promise.<Transaction>

Transfer token

Kind: instance method of ERC721

Param Type
args TransferContractToken

erC721.getDecodedTransfer(args) ⇒ string

get decoded Transfer

Kind: instance method of ERC721

Param Type
args TransferContractToken

erC721.getTokenUri(tokenId) ⇒ Promise.<string>

Get token uri, only works when this.type === 'ERC721'

Kind: instance method of ERC721

Param Type
tokenId string

erC721.transferEvents()

Subscribe on transfer events in contract

Kind: instance method of ERC721

StandardContract

The client describes how to work with ERC20, ERC721, ERC1155 contracts .

Kind: global class
Implements: IStandardContract

standardContract.init()

Gives access to contract methods, if you don't call init client just won't know which contract to use

Kind: instance method of StandardContract

standardContract.getBalance(object,) ⇒ Promise.<number>

Check balance in contract

Kind: instance method of StandardContract

Param Type
object, GetContractBalance

standardContract.transfer(args) ⇒ Promise.<Transaction>

Transfer token

Kind: instance method of StandardContract

Param Type
args TransferContractToken

standardContract.getTokenUri(tokenId) ⇒ Promise.<string>

Get token uri, only works when this.type === 'ERC721'

Kind: instance method of StandardContract

Param Type
tokenId string

standardContract.approve(object) ⇒ Promise.<ethers.providers.TransactionResponse>

Approve token for ERC20 and ERC721

Kind: instance method of StandardContract

Param Type
object ApproveToken

standardContract.setApprovalForAll(object) ⇒ Promise.<ethers.providers.TransactionResponse>

setApprovalForAll token for ERC721 and ERC1155

Kind: instance method of StandardContract

Param Type
object SetApprovalForAll

standardContract.transferEvents()

Subscribe on transfer events in contract

Kind: instance method of StandardContract

AnchorWrapper

The client describes how to work with Anchor.

Kind: global class
Implements: IAnchorWrapper

anchorWrapper.init() ⇒ LinkSession | null

init AnchorConnect library

Kind: instance method of AnchorWrapper

anchorWrapper.getBalance(coins) ⇒ Promise.<Array.<number>>

Get balance from current wallet in native coin

Kind: instance method of AnchorWrapper
Returns: Promise.<Array.<number>> -

  • balance value
Param Type Description
coins GetEosAccountInfoProps

anchorWrapper.getContractData(coins) ⇒ Promise.<Array.<number>>

Get balance from current wallet in contracts

Kind: instance method of AnchorWrapper
Returns: Promise.<Array.<number>> -

  • balance value
Param Type Description
coins GetEosAccountInfoProps

anchorWrapper.getAccountInfo(args) ⇒ Promise.<Array.<number>>

Get account info from current wallets in native coin

Kind: instance method of AnchorWrapper

Param Type Description
args GetEosAccountInfoProps

anchorWrapper.connectWallet() ⇒ Promise.<Array.<string>>

Get data for sign in via anchor

Kind: instance method of AnchorWrapper
Returns: Promise.<Array.<string>> -

  • wallet address

anchorWrapper.sendSignedTransaction(object) ⇒ Promise.<(TransactResult|undefined)>

Send Transaction with user's anchor

Kind: instance method of AnchorWrapper

Param Type
object SendEosSignedTransaction

anchorWrapper.sendTransaction(tx) ⇒ Promise.<SendTransactionResponse>

Send Transaction

Kind: instance method of AnchorWrapper

Param Type
tx SendEosTransaction

anchorWrapper.transfer(args) ⇒ TransactResult | undefined

Transfer native coin

Kind: instance method of AnchorWrapper

Param Type
args EosTransferProps

MetamaskWrapper

The client describes how to work with Metamask Extension.

Kind: global class
Implements: IMetamaskWrapper

new MetamaskWrapper()

Current class is Singleton

metamaskWrapper.generateWallet() ⇒ object

Generate Ethers wallet

Kind: instance method of MetamaskWrapper
Returns: object -

  • Object with address, mnemonic and privateKey

metamaskWrapper.connectWallet() ⇒ Promise.<Array.<string>>

Connect to Metamask Extension and return current wallet address if extension exists or open installation page

Kind: instance method of MetamaskWrapper
Returns: Promise.<Array.<string>> -

  • wallet address

metamaskWrapper.getAddress() ⇒ Promise.<Array.<string>>

Get current Metamask wallet address

Kind: instance method of MetamaskWrapper
Returns: Promise.<Array.<string>> -

  • wallet address

metamaskWrapper.getBalance(getBalanceProps, network, address) ⇒ Promise.<Array.<number>>

Get balance from current wallet in native coin

Kind: instance method of MetamaskWrapper
Returns: Promise.<Array.<number>> -

  • balance value
Param Type Description
getBalanceProps GetBalanceProps

custom props if balance in custom network and address needed

network ChainIds
address string

metamaskWrapper.getAccountInfo(accounts) ⇒ Promise.<Array.<AccountInfo>>

Get balance from current wallet in native coin

Kind: instance method of MetamaskWrapper
Returns: Promise.<Array.<AccountInfo>> -

  • balance value
Param Type Description
accounts Array.<GetBalanceProps>

metamaskWrapper.getChain() ⇒ Promise.<(ChainInfo|null)>

Get Chain

Kind: instance method of MetamaskWrapper
Returns: Promise.<(ChainInfo|null)> -

  • Chain class with chainId and name

metamaskWrapper.switchNetwork(chainId) ⇒ Promise.<void>

Switch to another chain network

Kind: instance method of MetamaskWrapper

Param Type Description
chainId ChainIds

id of Chain

metamaskWrapper.switchCustomNetwork(network) ⇒ Promise.<void>

Switch to custom chain network

Kind: instance method of MetamaskWrapper

Param Type Description
network AddEthereumChainParameter

Object of chain network

metamaskWrapper.addToken(token) ⇒ Promise.<boolean>

Add coin token (only ERC20 for now @metamask docs) to metamask

Kind: instance method of MetamaskWrapper

Param Type Description
token CoinsTypes

CoinsTypes, like USDT

metamaskWrapper.addCustomToken(newAsset) ⇒ Promise.<boolean>

Add custom token (only ERC20 for now @metamask docs) to metamask

Kind: instance method of MetamaskWrapper

Param Type Description
newAsset WatchAssetParams

Asset object

metamaskWrapper.sign(object) ⇒ Promise.<void>

Sign transaction with metamask

Kind: instance method of MetamaskWrapper

Param Type Description
object SignProps

Sign Object with type and message

metamaskWrapper.transfer(args) ⇒ Promise.<(ethers.providers.TransactionResponse|null)>

Transfer native coin

Kind: instance method of MetamaskWrapper

Param Type
args TransferToken

metamaskWrapper.sendSignedTransaction(tx) ⇒ Promise.<ethers.providers.TransactionResponse>

Send Transaction with user's metamask

Kind: instance method of MetamaskWrapper

Param Type Description
tx ethers.utils.Deferrable.<ethers.providers.TransactionRequest>

Transaction Request

metamaskWrapper.sendTransaction(tx) ⇒ Promise.<ethers.providers.TransactionResponse>

Send Transaction

Kind: instance method of MetamaskWrapper

Param Type Description
tx ethers.utils.Deferrable.<ethers.providers.TransactionRequest>

Transaction Request

metamaskWrapper.getMobileLink() ⇒ string

Get lint for mobile metamask

Kind: instance method of MetamaskWrapper

TrezorWrapper

The client describes how to work with Trezor.

Kind: global class
Implements: ITrezorWrapper

trezorWrapper.init(object) ⇒ Promise.<void>

init TrezorConnect library

Kind: instance method of TrezorWrapper

Param Type
object Manifest

trezorWrapper.getBalance(coins) ⇒ Promise.<Array.<number>>

Get balance from current wallet in native coin

Kind: instance method of TrezorWrapper
Returns: Promise.<Array.<number>> -

  • balance value
Param Type Description
coins Array.<AllCoins>

trezorWrapper.getAccountInfo(args) ⇒ Promise.<Array.<number>>

Get account info from current wallets in native coin

Kind: instance method of TrezorWrapper

Param Type Description
args Array.<GetAccountInfo>

trezorWrapper.connectWallet(params) ⇒ Promise.<Array.<string>>

Get data for sign in via trezor

Kind: instance method of TrezorWrapper
Returns: Promise.<Array.<string>> -

  • wallet address
Param Type
params Params.<(RequestLoginAsync|LoginChallenge)>

trezorWrapper.sendSignedTransaction(object) ⇒ Promise.<(SignedTransaction|PushedTransaction|CardanoSignedTxData|EosSignedTx)>

Send Transaction with user's trezor

Kind: instance method of TrezorWrapper

Param Type
object SendSignedTransactionProps

trezorWrapper.sendTransaction(object) ⇒ Promise.<PushedTransaction>

Send Transaction

Kind: instance method of TrezorWrapper

Param Type
object SendTransactionProps

trezorWrapper.transfer(args) ⇒ Promise.<(SignedTransaction|CardanoSignedTxData|EosSignedTx|PushedTransaction)>

Transfer native coin

Kind: instance method of TrezorWrapper

Param Type
args TransferProps

WalletsWrapper

The client describes how to work with all wallets. All connection to wallets must be with this client

Kind: global class
Implements: WalletWrapper

new WalletsWrapper(object, type, infuraApiKey)

Creates an instance of a class to work with a specific wallet

Param Type Description
object WalletsWrapperProps
type WalletsNames

type of wallet, default is MetamaskWrapper

infuraApiKey WalletsWrapperProps

the parameter is needed to connect to the blockchain

walletsWrapper.init(object) ⇒ Promise.<void>

init library

Kind: instance method of WalletsWrapper

Param Type
object Manifest

walletsWrapper.isInstalled() ⇒ Promise.<boolean>

Check wallet existing

Kind: instance method of WalletsWrapper

walletsWrapper.connectWallet(params) ⇒ Promise.<Array.<string>>

Connect to chosen wallet

Kind: instance method of WalletsWrapper
Returns: Promise.<Array.<string>> -

  • wallet address
Param Type Description
params Params.<(RequestLoginAsync|LoginChallenge)>

params for trezor

walletsWrapper.getChain(object) ⇒ Promise.<Array.<string>>

Get current wallet addresses

Kind: instance method of WalletsWrapper
Returns: Promise.<Array.<string>> -

  • wallet address
Param Type
object GetAddressProps

walletsWrapper.getStandardContract(address, network) ⇒ Promise.<StandardContract>

Get client for contract connection

Kind: instance method of WalletsWrapper

Param Type Description
address string

Contract address

network ChainIds

network in which to search for a contract

ErrorTypes : enum

Description of errors

Kind: global enum
Read only: true

generateCoin : enum

Types of ERC20 tokens

Kind: global enum
Read only: true

networks : enum

Types of supported EVM networks

Kind: global enum
Read only: true
Properties

Name Type Default
"_models.ChainIds.EthereumMainNetwork" string "{&quot;chainId&quot;:&quot;&quot;,&quot;chainName&quot;:&quot;&quot;,&quot;nativeCurrency&quot;:&quot;&quot;,&quot;rpcUrls&quot;:&quot;&quot;}"
"_models.ChainIds.RopstenTestNetwork" string "{&quot;chainId&quot;:&quot;&quot;,&quot;chainName&quot;:&quot;&quot;,&quot;nativeCurrency&quot;:&quot;&quot;,&quot;rpcUrls&quot;:&quot;&quot;}"
"_models.ChainIds.RinkebyTestNetwork" string "{&quot;chainId&quot;:&quot;&quot;,&quot;chainName&quot;:&quot;Rinkeby Test Network&quot;,&quot;nativeCurrency&quot;:&quot;&quot;,&quot;rpcUrls&quot;:&quot;&quot;}"
"_models.ChainIds.GoerliTestNetwork" string "{&quot;chainId&quot;:&quot;&quot;,&quot;chainName&quot;:&quot;&quot;,&quot;nativeCurrency&quot;:&quot;&quot;,&quot;rpcUrls&quot;:&quot;&quot;}"
"_models.ChainIds.KovanTestNetwork" string "{&quot;chainId&quot;:&quot;&quot;,&quot;chainName&quot;:&quot;Kovan Test Network&quot;,&quot;nativeCurrency&quot;:&quot;&quot;,&quot;rpcUrls&quot;:&quot;&quot;}"
"_models.ChainIds.PolygonMainnet" string "{&quot;chainId&quot;:&quot;&quot;,&quot;chainName&quot;:&quot;Polygon Mainnet&quot;,&quot;nativeCurrency&quot;:&quot;&quot;,&quot;rpcUrls&quot;:&quot;&quot;}"
"_models.ChainIds.HardhatLocalhost" string "{&quot;chainId&quot;:&quot;&quot;,&quot;chainName&quot;:&quot;Hardhat Localhost&quot;,&quot;nativeCurrency&quot;:&quot;&quot;,&quot;rpcUrls&quot;:&quot;&quot;}"
"_models.ChainIds.GanacheLocalhost" string "{&quot;chainId&quot;:&quot;&quot;,&quot;chainName&quot;:&quot;Ganache Localhost&quot;,&quot;nativeCurrency&quot;:&quot;&quot;,&quot;rpcUrls&quot;:&quot;&quot;}"
"_models.ChainIds.BinanceSmartChain" string "{&quot;chainId&quot;:&quot;&quot;,&quot;chainName&quot;:&quot;&quot;,&quot;nativeCurrency&quot;:&quot;&quot;,&quot;rpcUrls&quot;:&quot;&quot;,&quot;blockExplorerUrls&quot;:&quot;&quot;}"
"_models.ChainIds.BinanceSmartTestnet" string "{&quot;chainId&quot;:&quot;&quot;,&quot;chainName&quot;:&quot;&quot;,&quot;nativeCurrency&quot;:&quot;&quot;,&quot;rpcUrls&quot;:&quot;&quot;,&quot;blockExplorerUrls&quot;:&quot;&quot;}"
"_models.ChainIds.Palm" string "{&quot;chainId&quot;:&quot;&quot;,&quot;chainName&quot;:&quot;&quot;,&quot;nativeCurrency&quot;:&quot;&quot;,&quot;rpcUrls&quot;:&quot;&quot;,&quot;blockExplorerUrls&quot;:&quot;&quot;}"
"_models.ChainIds.PalmTestnet" string "{&quot;chainId&quot;:&quot;&quot;,&quot;chainName&quot;:&quot;&quot;,&quot;nativeCurrency&quot;:&quot;&quot;,&quot;rpcUrls&quot;:&quot;&quot;,&quot;blockExplorerUrls&quot;:&quot;&quot;}"

Package Sidebar

Install

npm i wallets-wrapper

Weekly Downloads

17

Version

0.0.35

License

ISC

Unpacked Size

2.72 MB

Total Files

119

Last publish

Collaborators

  • lastskywalker