0.0.37 • Published 3 years ago

@erfffun/energi-wallet v0.0.37

Weekly downloads
-
License
GPL-3.0-or-later
Repository
-
Last release
3 years ago

Energi Wallets

npm version NPM Discord npm node-current

Requirements

  • nodejs v16.10.0
  • yarn v1.22.11

Build

yarn
yarn build

Publish

yarn login
yarn publish

How to use

Install

Add the library to your project by the following commands:

npm install @energi/energi-wallet
# or
yarn add @energi/energi-wallet

Usage

import { useMetamask } from '@energi/energi-wallet';

const MyComponent = () => {
  const { connected, connect, disconnect, switchToNetwork } = useMetamask();
  const RINKEBY_CHAIN_ID = 4;

  return (
    <button onClick={() => connected ? disconnect() : connect()}>
      {connected ? 'Disconnect' : 'Connect'}
    </button>
    <button onClick={() => switchToNetwork(RINKEBY_CHAIN_ID)}>
      Switch to Rinkeby network
    </button>
  )
}

Send Transaction Example

// import section ...
import { Metamask } from '@energi/energi-wallet';

// Component body ...
const { sendTx } = Metamask;
const handleSendTransaction = async (data) => {
  try {
    const tx = await sendTx(data);
    return tx;
  } catch(error) {
    throw new Error(`Transaction failed: ${error}`)
  }
  return null;
}

// On an event ...
handleSendTransaction({
  from: 'wallet_address',
  to: 'to_wallet_or_contract',
  gasLimit: 'gas_limit_to_hex',
  data: 'encoded_tx_data'
})

Currently, only metamask is supported.

Methods and Properties

Hooks

  • useMetamask

Properties

  • installed: if the wallet is installed
  • connected: if the wallet is connected
  • chainId: the network/chain ID
  • address: the wallet address
  • accounts: all accounts/addresses related to the wallet

Methods

  • connect: connects to the wallet
  • disconnect: disconnects the app from the wallet
  • switchToNetwork: switches the network or chain
  • sendTx: for sending transaction from metamask
  • addNewToken: adding a new token to the metamask
  • sign: Sign messages with the private key of the address

Classes

  • Metamask

Methods

  • isInstalled: returns if the wallet is installed
  • isConnected: returns if the wallet is connected
  • getChainId: returns the network/chain ID
  • getAddress: returns the wallet address
  • getAccounts: returns all accounts/addresses related to the wallet
  • connect: connects the the wallet
  • disconnect: disconnects the app from the wallet
  • switchToNetwork: switches the network or chain
  • sendTx: for sending transaction from metamask
  • addNewToken: adding a new token to the metamask
  • sign: Sign messages with the private key of the address
  • getMetaMask: Returns the web3 provider

Disclaimer

Filing an issue does not guarantee addition to this package.

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

0.0.37

3 years ago

1.0.25

3 years ago

0.0.32

3 years ago

0.0.33

3 years ago

0.0.34

3 years ago

0.0.35

3 years ago

0.0.36

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago