1.0.6 • Published 2 years ago

@energi/energi-wallet v1.0.6

Weekly downloads
-
License
GPL-3.0-or-later
Repository
-
Last release
2 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.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago