A simple react hook for accessing Ethereum in any react application.
yarn add use-ethereum
Wrap you React application in the <EthereumProvider />
component. Any component nested under the EthereumProvider can access Ethereum by calling the useEthereum
hook.
const ethereum = useEthereum()
An HOC withEthereum
is also provided.
In order for this package to support as many platforms as possible the private key storage is generic and must be implemented by you. In the examples folder you can find an implementation for an Expo React Native app.
The following interface must be implemented and passed into the EthereumProvider
as a storage
props:
interface WalletStorage {
getWalletPublicKey: () => Promise<string | null>
getWalletPrivateKey: () => Promise<string | null>
setWallet: (args: {
publicKey: string
privateKey: string
mnemonic: string
}) => Promise<void>
removeWallet: () => Promise<void>
}