@erfffun/energi-wallet
TypeScript icon, indicating that this package has built-in type declarations

0.0.37 • Public • Published

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.

Package Sidebar

Install

npm i @erfffun/energi-wallet

Weekly Downloads

0

Version

0.0.37

License

GPL-3.0-or-later

Unpacked Size

29.7 kB

Total Files

20

Last publish

Collaborators

  • erfffun