⚠️ This project is deprecated. We are no longer actively developing new features nor addressing issues. Read here for more info, and reach out if you are interested in taking over maintenance. We suggest looking into web3-react for a popular alternative to this project.
openzeppelin-network.js
One line access to Web3 in your dApp.
- Hides various Web3 providers behind common API.
- One line access to the Web3 providers (Metamask, Infura, Geth, Portis and etc).
- Supports multiple Web3 providers within the same app.
- First class support of meta-txs.
- React integration using hooks.
- Network, accounts, and connection changed events for all web3 providers.
- Will fire events even for HTTP and forcefully terminated providers.
Overview
Installation
npm install @openzeppelin/network
Usage
With React Hooks
Import the library:
;
Get Web3Context with React Hooks inside functional component:
const injected = ;const local = ;
Use Web3Context
to get fresh data:
const accounts networkId networkName providerName lib connected = web3Context;
Network.js will re-render component when network, accounts or connetion state change.
To use GSN with any hook specify GSN as an option, providing a signing key:
;
With Vanilla Javascript
Import the library:
;
Get Web3Context
:
const injected = await ;const local = await ;
To use GSN include a gsn
option, including a signing key:
;
Use Web3Context
to get fresh data immediately:
const accounts networkId networkName providerName lib connected = web3Context;
Subscribe to events to get notified:
{} {} {} web3Context;web3Context;web3Context;
Unsubscribe from events once you don't need them:
web3Context;web3Context;web3Context;
Learn More
- Try it out on the GSN Starter Kit: run
npx @openzeppelin/cli unpack gsn
in a new directory and follow the instructions. - For detailed usage information, take a look at the API Reference.
License
Released under the MIT License.