wallets-wrapper
v0.0.35
Published
How to install
Downloads
76
Maintainers
Readme
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: '[email protected]',
})
.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
Kind: global class
Implements: IStandardContract
- ERC1155
- .init()
- .getBalance(object,) ⇒ Promise.<number>
- .transfer(args) ⇒ Promise.<Transaction>
- .getDecodedTransfer(args) ⇒ string
- .getTokenUri(tokenId) ⇒ Promise.<string>
- .transferEvents()
erC1155.init()
Kind: instance method of ERC1155
erC1155.getBalance(object,) ⇒ Promise.<number>
Kind: instance method of ERC1155
| Param | Type | | --- | --- | | object, | GetContractBalance |
erC1155.transfer(args) ⇒ Promise.<Transaction>
Kind: instance method of ERC1155
| Param | Type | | --- | --- | | args | TransferContractToken |
erC1155.getDecodedTransfer(args) ⇒ string
Kind: instance method of ERC1155
| Param | Type | | --- | --- | | args | TransferContractToken |
erC1155.getTokenUri(tokenId) ⇒ Promise.<string>
Kind: instance method of ERC1155
| Param | Type | | --- | --- | | tokenId | string |
erC1155.transferEvents()
Kind: instance method of ERC1155
ERC20
Kind: global class
Implements: IStandardContract
- ERC20
- .init()
- .getBalance(object,) ⇒ Promise.<number>
- .transfer(args) ⇒ Promise.<Transaction>
- .getDecodedTransfer(args) ⇒ string
- .transferEvents()
erC20.init()
Kind: instance method of ERC20
erC20.getBalance(object,) ⇒ Promise.<number>
Kind: instance method of ERC20
| Param | Type | | --- | --- | | object, | GetContractBalance |
erC20.transfer(args) ⇒ Promise.<Transaction>
Kind: instance method of ERC20
| Param | Type | | --- | --- | | args | TransferContractToken |
erC20.getDecodedTransfer(args) ⇒ string
Kind: instance method of ERC20
| Param | Type | | --- | --- | | args | TransferContractToken |
erC20.transferEvents()
Kind: instance method of ERC20
ERC721
Kind: global class
Implements: IStandardContract
- ERC721
- .init()
- .getBalance(address,, object,) ⇒ Promise.<number>
- .transfer(args) ⇒ Promise.<Transaction>
- .getDecodedTransfer(args) ⇒ string
- .getTokenUri(tokenId) ⇒ Promise.<string>
- .transferEvents()
erC721.init()
Kind: instance method of ERC721
erC721.getBalance(address,, object,) ⇒ Promise.<number>
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>
Kind: instance method of ERC721
| Param | Type | | --- | --- | | args | TransferContractToken |
erC721.getDecodedTransfer(args) ⇒ string
Kind: instance method of ERC721
| Param | Type | | --- | --- | | args | TransferContractToken |
erC721.getTokenUri(tokenId) ⇒ Promise.<string>
Kind: instance method of ERC721
| Param | Type | | --- | --- | | tokenId | string |
erC721.transferEvents()
Kind: instance method of ERC721
StandardContract
Kind: global class
Implements: IStandardContract
- StandardContract
- .init()
- .getBalance(object,) ⇒ Promise.<number>
- .transfer(args) ⇒ Promise.<Transaction>
- .getTokenUri(tokenId) ⇒ Promise.<string>
- .approve(object) ⇒ Promise.<ethers.providers.TransactionResponse>
- .setApprovalForAll(object) ⇒ Promise.<ethers.providers.TransactionResponse>
- .transferEvents()
standardContract.init()
Kind: instance method of StandardContract
standardContract.getBalance(object,) ⇒ Promise.<number>
Kind: instance method of StandardContract
| Param | Type | | --- | --- | | object, | GetContractBalance |
standardContract.transfer(args) ⇒ Promise.<Transaction>
Kind: instance method of StandardContract
| Param | Type | | --- | --- | | args | TransferContractToken |
standardContract.getTokenUri(tokenId) ⇒ Promise.<string>
Kind: instance method of StandardContract
| Param | Type | | --- | --- | | tokenId | string |
standardContract.approve(object) ⇒ Promise.<ethers.providers.TransactionResponse>
Kind: instance method of StandardContract
| Param | Type | | --- | --- | | object | ApproveToken |
standardContract.setApprovalForAll(object) ⇒ Promise.<ethers.providers.TransactionResponse>
Kind: instance method of StandardContract
| Param | Type | | --- | --- | | object | SetApprovalForAll |
standardContract.transferEvents()
Kind: instance method of StandardContract
AnchorWrapper
Kind: global class
Implements: IAnchorWrapper
- AnchorWrapper
- .init() ⇒ LinkSession | null
- .getBalance(coins) ⇒ Promise.<Array.<number>>
- .getContractData(coins) ⇒ Promise.<Array.<number>>
- .getAccountInfo(args) ⇒ Promise.<Array.<number>>
- .connectWallet() ⇒ Promise.<Array.<string>>
- .sendSignedTransaction(object) ⇒ Promise.<(TransactResult|undefined)>
- .sendTransaction(tx) ⇒ Promise.<SendTransactionResponse>
- .transfer(args) ⇒ TransactResult | undefined
anchorWrapper.init() ⇒ LinkSession | null
Kind: instance method of AnchorWrapper
anchorWrapper.getBalance(coins) ⇒ Promise.<Array.<number>>
Kind: instance method of AnchorWrapper
Returns: Promise.<Array.<number>> -
| Param | Type | Description | | --- | --- | --- | | coins | GetEosAccountInfoProps | |
anchorWrapper.getContractData(coins) ⇒ Promise.<Array.<number>>
Kind: instance method of AnchorWrapper
Returns: Promise.<Array.<number>> -
| Param | Type | Description | | --- | --- | --- | | coins | GetEosAccountInfoProps | |
anchorWrapper.getAccountInfo(args) ⇒ Promise.<Array.<number>>
Kind: instance method of AnchorWrapper
| Param | Type | Description | | --- | --- | --- | | args | GetEosAccountInfoProps | |
anchorWrapper.connectWallet() ⇒ Promise.<Array.<string>>
Kind: instance method of AnchorWrapper
Returns: Promise.<Array.<string>> -
anchorWrapper.sendSignedTransaction(object) ⇒ Promise.<(TransactResult|undefined)>
Kind: instance method of AnchorWrapper
| Param | Type | | --- | --- | | object | SendEosSignedTransaction |
anchorWrapper.sendTransaction(tx) ⇒ Promise.<SendTransactionResponse>
Kind: instance method of AnchorWrapper
| Param | Type | | --- | --- | | tx | SendEosTransaction |
anchorWrapper.transfer(args) ⇒ TransactResult | undefined
Kind: instance method of AnchorWrapper
| Param | Type | | --- | --- | | args | EosTransferProps |
MetamaskWrapper
Kind: global class
Implements: IMetamaskWrapper
- MetamaskWrapper
- new MetamaskWrapper()
- .generateWallet() ⇒ object
- .connectWallet() ⇒ Promise.<Array.<string>>
- .getAddress() ⇒ Promise.<Array.<string>>
- .getBalance(getBalanceProps, network, address) ⇒ Promise.<Array.<number>>
- .getAccountInfo(accounts) ⇒ Promise.<Array.<AccountInfo>>
- .getChain() ⇒ Promise.<(ChainInfo|null)>
- .switchNetwork(chainId) ⇒ Promise.<void>
- .switchCustomNetwork(network) ⇒ Promise.<void>
- .addToken(token) ⇒ Promise.<boolean>
- .addCustomToken(newAsset) ⇒ Promise.<boolean>
- .sign(object) ⇒ Promise.<void>
- .transfer(args) ⇒ Promise.<(ethers.providers.TransactionResponse|null)>
- .sendSignedTransaction(tx) ⇒ Promise.<ethers.providers.TransactionResponse>
- .sendTransaction(tx) ⇒ Promise.<ethers.providers.TransactionResponse>
- .getMobileLink() ⇒ string
new MetamaskWrapper()
metamaskWrapper.generateWallet() ⇒ object
Kind: instance method of MetamaskWrapper
Returns: object -
metamaskWrapper.connectWallet() ⇒ Promise.<Array.<string>>
Kind: instance method of MetamaskWrapper
Returns: Promise.<Array.<string>> -
metamaskWrapper.getAddress() ⇒ Promise.<Array.<string>>
Kind: instance method of MetamaskWrapper
Returns: Promise.<Array.<string>> -
metamaskWrapper.getBalance(getBalanceProps, network, address) ⇒ Promise.<Array.<number>>
Kind: instance method of MetamaskWrapper
Returns: Promise.<Array.<number>> -
| 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>>
Kind: instance method of MetamaskWrapper
Returns: Promise.<Array.<AccountInfo>> -
| Param | Type | Description | | --- | --- | --- | | accounts | Array.<GetBalanceProps> | |
metamaskWrapper.getChain() ⇒ Promise.<(ChainInfo|null)>
Kind: instance method of MetamaskWrapper
Returns: Promise.<(ChainInfo|null)> -
metamaskWrapper.switchNetwork(chainId) ⇒ Promise.<void>
Kind: instance method of MetamaskWrapper
| Param | Type | Description | | --- | --- | --- | | chainId | ChainIds | id of Chain |
metamaskWrapper.switchCustomNetwork(network) ⇒ Promise.<void>
Kind: instance method of MetamaskWrapper
| Param | Type | Description | | --- | --- | --- | | network | AddEthereumChainParameter | Object of chain network |
metamaskWrapper.addToken(token) ⇒ Promise.<boolean>
Kind: instance method of MetamaskWrapper
| Param | Type | Description | | --- | --- | --- | | token | CoinsTypes | CoinsTypes, like USDT |
metamaskWrapper.addCustomToken(newAsset) ⇒ Promise.<boolean>
Kind: instance method of MetamaskWrapper
| Param | Type | Description | | --- | --- | --- | | newAsset | WatchAssetParams | Asset object |
metamaskWrapper.sign(object) ⇒ Promise.<void>
Kind: instance method of MetamaskWrapper
| Param | Type | Description | | --- | --- | --- | | object | SignProps | Sign Object with type and message |
metamaskWrapper.transfer(args) ⇒ Promise.<(ethers.providers.TransactionResponse|null)>
Kind: instance method of MetamaskWrapper
| Param | Type | | --- | --- | | args | TransferToken |
metamaskWrapper.sendSignedTransaction(tx) ⇒ Promise.<ethers.providers.TransactionResponse>
Kind: instance method of MetamaskWrapper
| Param | Type | Description | | --- | --- | --- | | tx | ethers.utils.Deferrable.<ethers.providers.TransactionRequest> | Transaction Request |
metamaskWrapper.sendTransaction(tx) ⇒ Promise.<ethers.providers.TransactionResponse>
Kind: instance method of MetamaskWrapper
| Param | Type | Description | | --- | --- | --- | | tx | ethers.utils.Deferrable.<ethers.providers.TransactionRequest> | Transaction Request |
metamaskWrapper.getMobileLink() ⇒ string
Kind: instance method of MetamaskWrapper
TrezorWrapper
Kind: global class
Implements: ITrezorWrapper
- TrezorWrapper
- .init(object) ⇒ Promise.<void>
- .getBalance(coins) ⇒ Promise.<Array.<number>>
- .getAccountInfo(args) ⇒ Promise.<Array.<number>>
- .connectWallet(params) ⇒ Promise.<Array.<string>>
- .sendSignedTransaction(object) ⇒ Promise.<(SignedTransaction|PushedTransaction|CardanoSignedTxData|EosSignedTx)>
- .sendTransaction(object) ⇒ Promise.<PushedTransaction>
- .transfer(args) ⇒ Promise.<(SignedTransaction|CardanoSignedTxData|EosSignedTx|PushedTransaction)>
trezorWrapper.init(object) ⇒ Promise.<void>
Kind: instance method of TrezorWrapper
| Param | Type | | --- | --- | | object | Manifest |
trezorWrapper.getBalance(coins) ⇒ Promise.<Array.<number>>
Kind: instance method of TrezorWrapper
Returns: Promise.<Array.<number>> -
| Param | Type | Description | | --- | --- | --- | | coins | Array.<AllCoins> | |
trezorWrapper.getAccountInfo(args) ⇒ Promise.<Array.<number>>
Kind: instance method of TrezorWrapper
| Param | Type | Description | | --- | --- | --- | | args | Array.<GetAccountInfo> | |
trezorWrapper.connectWallet(params) ⇒ Promise.<Array.<string>>
Kind: instance method of TrezorWrapper
Returns: Promise.<Array.<string>> -
| Param | Type | | --- | --- | | params | Params.<(RequestLoginAsync|LoginChallenge)> |
trezorWrapper.sendSignedTransaction(object) ⇒ Promise.<(SignedTransaction|PushedTransaction|CardanoSignedTxData|EosSignedTx)>
Kind: instance method of TrezorWrapper
| Param | Type | | --- | --- | | object | SendSignedTransactionProps |
trezorWrapper.sendTransaction(object) ⇒ Promise.<PushedTransaction>
Kind: instance method of TrezorWrapper
| Param | Type | | --- | --- | | object | SendTransactionProps |
trezorWrapper.transfer(args) ⇒ Promise.<(SignedTransaction|CardanoSignedTxData|EosSignedTx|PushedTransaction)>
Kind: instance method of TrezorWrapper
| Param | Type | | --- | --- | | args | TransferProps |
WalletsWrapper
Kind: global class
Implements: WalletWrapper
- WalletsWrapper
- new WalletsWrapper(object, type, infuraApiKey)
- .init(object) ⇒ Promise.<void>
- .isInstalled() ⇒ Promise.<boolean>
- .connectWallet(params) ⇒ Promise.<Array.<string>>
- .getChain(object) ⇒ Promise.<Array.<string>>
- .getStandardContract(address, network) ⇒ Promise.<StandardContract>
new WalletsWrapper(object, type, infuraApiKey)
| 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>
Kind: instance method of WalletsWrapper
| Param | Type | | --- | --- | | object | Manifest |
walletsWrapper.isInstalled() ⇒ Promise.<boolean>
Kind: instance method of WalletsWrapper
walletsWrapper.connectWallet(params) ⇒ Promise.<Array.<string>>
Kind: instance method of WalletsWrapper
Returns: Promise.<Array.<string>> -
| Param | Type | Description | | --- | --- | --- | | params | Params.<(RequestLoginAsync|LoginChallenge)> | params for trezor |
walletsWrapper.getChain(object) ⇒ Promise.<Array.<string>>
Kind: instance method of WalletsWrapper
Returns: Promise.<Array.<string>> -
| Param | Type | | --- | --- | | object | GetAddressProps |
walletsWrapper.getStandardContract(address, network) ⇒ Promise.<StandardContract>
Kind: instance method of WalletsWrapper
| Param | Type | Description | | --- | --- | --- | | address | string | Contract address | | network | ChainIds | network in which to search for a contract |
ErrorTypes : enum
Kind: global enum
Read only: true
generateCoin : enum
Kind: global enum
Read only: true
networks : enum
Kind: global enum
Read only: true
Properties
| Name | Type | Default | | --- | --- | --- | | "_models.ChainIds.EthereumMainNetwork" | string | "{"chainId":"","chainName":"","nativeCurrency":"","rpcUrls":""}" | | "_models.ChainIds.RopstenTestNetwork" | string | "{"chainId":"","chainName":"","nativeCurrency":"","rpcUrls":""}" | | "_models.ChainIds.RinkebyTestNetwork" | string | "{"chainId":"","chainName":"Rinkeby Test Network","nativeCurrency":"","rpcUrls":""}" | | "_models.ChainIds.GoerliTestNetwork" | string | "{"chainId":"","chainName":"","nativeCurrency":"","rpcUrls":""}" | | "_models.ChainIds.KovanTestNetwork" | string | "{"chainId":"","chainName":"Kovan Test Network","nativeCurrency":"","rpcUrls":""}" | | "_models.ChainIds.PolygonMainnet" | string | "{"chainId":"","chainName":"Polygon Mainnet","nativeCurrency":"","rpcUrls":""}" | | "_models.ChainIds.HardhatLocalhost" | string | "{"chainId":"","chainName":"Hardhat Localhost","nativeCurrency":"","rpcUrls":""}" | | "_models.ChainIds.GanacheLocalhost" | string | "{"chainId":"","chainName":"Ganache Localhost","nativeCurrency":"","rpcUrls":""}" | | "_models.ChainIds.BinanceSmartChain" | string | "{"chainId":"","chainName":"","nativeCurrency":"","rpcUrls":"","blockExplorerUrls":""}" | | "_models.ChainIds.BinanceSmartTestnet" | string | "{"chainId":"","chainName":"","nativeCurrency":"","rpcUrls":"","blockExplorerUrls":""}" | | "_models.ChainIds.Palm" | string | "{"chainId":"","chainName":"","nativeCurrency":"","rpcUrls":"","blockExplorerUrls":""}" | | "_models.ChainIds.PalmTestnet" | string | "{"chainId":"","chainName":"","nativeCurrency":"","rpcUrls":"","blockExplorerUrls":""}" |