Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@walletconnect/web3-provider
Advanced tools
Web3 Provider for WalletConnect
For more details, read the documentation
import Web3 from "web3";
import WalletConnectProvider from "@walletconnect/web3-provider";
// Create WalletConnect Provider
const provider = new WalletConnectProvider({
infuraId: "27e484dcd9e3efcfd25a83a78777cdf1", // Required
});
// Enable session (triggers QR Code modal)
await provider.enable();
// Create Web3
const web3 = new Web3(provider);
// Subscribe to accounts change
provider.on("accountsChanged", (accounts: string[]) => {
console.log(accounts);
});
// Subscribe to chainId change
provider.on("chainChanged", (chainId: number) => {
console.log(chainId);
});
// Subscribe to session connection
provider.on("connect", () => {
console.log("connect");
});
// Subscribe to session disconnection
provider.on("disconnect", (code: number, reason: string) => {
console.log(code, reason);
});
interface RequestArguments {
method: string;
params?: unknown[] | object;
}
// Send JSON RPC requests
const result = await provider.request(payload: RequestArguments);
// Close provider session
await provider.disconnect()
// Get Accounts
const accounts = await web3.eth.getAccounts();
// Get Chain Id
const chainId = await web3.eth.chainId();
// Get Network Id
const networkId = await web3.eth.net.getId();
// Send Transaction
const txHash = await web3.eth.sendTransaction(tx);
// Sign Transaction
const signedTx = await web3.eth.signTransaction(tx);
// Sign Message
const signedMessage = await web3.eth.sign(msg);
// Sign Typed Data
const signedTypedData = await web3.eth.signTypedData(msg);
In order to resolve non-signing requests you need to provide one of the following:
The infuraId will support the following chainId's: Mainnet (1), Ropsten (3), Rinkeby(4), Goerli (5) and Kovan (42)
const provider = new WalletConnectProvider({
infuraId: "27e484dcd9e3efcfd25a83a78777cdf1",
});
The RPC URL mapping should indexed by chainId and it requires at least one value.
const provider = new WalletConnectProvider({
rpc: {
1: "https://mainnet.mycustomnode.com",
3: "https://ropsten.mycustomnode.com",
100: "https://dai.poa.network",
// ...
},
});
You can also customize the connector through the provider using the following options
Use your own hosted bridge by providing the url
const provider = new WalletConnectProvider({
infuraId: "27e484dcd9e3efcfd25a83a78777cdf1",
bridge: "https://bridge.myhostedserver.com",
});
Use your own custom qrcode modal and disable the built-in one
const provider = new WalletConnectProvider({
infuraId: "27e484dcd9e3efcfd25a83a78777cdf1",
qrcode: false,
});
provider.connector.on("display_uri", (err, payload) => {
const uri = payload.params[0];
CustomQRCodeModal.display(uri);
});
If you would like to reduce the number of linking options or customize its order, you can provide an array of wallet names. Providing empty whitelist disables linking.
const provider = new WalletConnectProvider({
infuraId: "27e484dcd9e3efcfd25a83a78777cdf1",
qrcodeModalOptions: {
mobileLinks: [
"rainbow",
"metamask",
"argent",
"trust",
"imtoken",
"pillar",
],
desktopLinks: [
"encrypted ink",
]
}
});
FAQs
Web3 Provider for WalletConnect
The npm package @walletconnect/web3-provider receives a total of 21,650 weekly downloads. As such, @walletconnect/web3-provider popularity was classified as popular.
We found that @walletconnect/web3-provider 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.