
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
@openzeppelin/network
Advanced tools
An easy to use and reliable library that provides one line access to Web3 API.
:warning: 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.
One line access to Web3 in your dApp.
npm install @openzeppelin/network
Import the library:
import { useWeb3Injected, useWeb3Network, useEphemeralKey } from '@openzeppelin/network/react';
Get Web3Context with React Hooks inside functional component:
const injected = useWeb3Injected();
const local = useWeb3Network('http://127.0.0.1:8545');
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:
const local = useWeb3Network('http://127.0.0.1:8545', {
gsn: { signKey: useEphemeralKey() }
});
Import the library:
import { fromInjected, fromConnection } from '@openzeppelin/network';
Get Web3Context
:
const injected = await fromInjected();
const local = await fromConnection('http://127.0.0.1:8545');
To use GSN include a gsn
option, including a signing key:
const local = await fromConnection('http://127.0.0.1:8545', {
gsn: { signKey: ephemeral() }
});
Use Web3Context
to get fresh data immediately:
const { accounts, networkId, networkName, providerName, lib, connected } = web3Context;
Subscribe to events to get notified:
function updateNetwork(networkId, networkName) {}
function updateAccounts(accounts) {}
function updateConnection(connected) {}
web3Context.on(Web3Context.NetworkIdChangedEventName, updateNetwork);
web3Context.on(Web3Context.AccountsChangedEventName, updateAccounts);
web3Context.on(Web3Context.ConnectionChangedEventName, updateConnection);
Unsubscribe from events once you don't need them:
web3Context.off(Web3Context.NetworkIdChangedEventName, updateNetwork);
web3Context.off(Web3Context.AccountsChangedEventName, updateAccounts);
web3Context.off(Web3Context.ConnectionChangedEventName, updateConnection);
npx @openzeppelin/cli unpack gsn
in a new directory and follow the instructions.Released under the MIT License.
FAQs
An easy to use and reliable library that provides one line access to Web3 API.
The npm package @openzeppelin/network receives a total of 10 weekly downloads. As such, @openzeppelin/network popularity was classified as not popular.
We found that @openzeppelin/network demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.