Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
@web3modal/react
Advanced tools
Make sure to read our main readme first to find out details about projectId, chain specific packages and modal customisation options.
npm install @web3modal/react @web3modal/ethereum
See @web3modal/ethereum readme for all available ethereum
options. NextJS example is also awailable in examples/react folder.
import type { ConfigOptions } from '@web3modal/react'
import { Web3ModalProvider } from '@web3modal/react'
const config: ConfigOptions = {
projectId: '<YOUR_PROJECT_ID>',
theme: 'dark',
accentColor: 'default',
ethereum: {
appName: 'web3Modal'
}
}
export default function App() {
return <Web3ModalProvider config={config}>{/* Rest of your app */}</Web3ModalProvider>
}
Please refer to hooks folder for more detailed info abut usage and argument / return types.
Hook to open, close and check state of the connect modal
import { useConnectModal } from '@web3modal/ethereum'
const { isOpen, open, close } = useConnectModal()
Hook to get account data
import { useAccount } from '@web3modal/ethereum'
const { chainSupported, address, chainId, connector } = useAccount()
Hook to get account data
import { useBalance } from '@web3modal/ethereum'
interface Options {
addressOrName: string
chainId: string // CAIP format i.e. Ethereum would be eip155:1
formatUnits: FetchBalanceArgs['formatUnits']
}
const { refetch, isLoading, error, balance } = useBalance(options)
Hook to get network data
import { useNetwork } from '@web3modal/ethereum'
const { chain, chains } = useNetwork()
Hook to get ethers signer
import { useSigner } from '@web3modal/ethereum'
const { refetch, isLoading, error, signer } = useSigner()
Hook to crate and handle sign message request
import { useSignMessage } from '@web3modal/ethereum'
const { isLoading, error, signature, sign } = useSignMessage()
Hook to crate and handle sign typed data request
import { useSignTypedData } from '@web3modal/ethereum'
const { isLoading, error, signature, sign } = useSignTypedData()
Hook to switch between supported networks
import { useSwitchNetork } from '@web3modal/ethereum'
const { isLoading, error, chainId, switchChain } = useSwitchNetork()
Hook to get contract details
import { useContract } from '@web3modal/ethereum'
interface Options {
addressOrName: string
contractInterface: GetContractArgs['contractInterface']
signerOrProvider: GetContractArgs['signerOrProvider']
}
const { refetch, error, contract } = useContract(options)
Hook to subscribe / receive contract events
import { useContractEvent } from '@web3modal/ethereum'
interface Options {
addressOrName: string
contractInterface: GetContractArgs['contractInterface']
signerOrProvider: GetContractArgs['signerOrProvider']
event: string
handler: (args: unknown[]) => void
once: boolean
}
const { refetch, error, contract } = useContractEvent(options)
Hook to read from contract
import { useContractRead } from '@web3modal/ethereum'
interface Options {
addressOrName: string
functionName: string
contractInterface: ReadContractConfig['contractInterface']
args: unknown
chainId: string
overrides: ReadContractConfig['overrides']
}
const { refetch, isLoading, error, read } = useContractRead(options)
Hook to write to contract
import { useContractWrite } from '@web3modal/ethereum'
interface Options {
addressOrName: string
functionName: string
contractInterface: ReadContractConfig['contractInterface']
args: unknown
chainId: string
overrides: ReadContractConfig['overrides']
request: Exclude<WriteContractArgs['request'], undefined>
}
const { data, refetch, isLoading, error } = useContractWrite(options)
Hook to prepare for contract write
import { usePrepareContractWrite } from '@web3modal/ethereum'
interface Options {
addressOrName: string
functionName: string
contractInterface: ReadContractConfig['contractInterface']
args: unknown
chainId: string
overrides: ReadContractConfig['overrides']
request: Exclude<WriteContractArgs['request'], undefined>
}
const { write, refetch, isLoading, error } = usePrepareContractWrite(options)
Hook to get token data
import { useToken } from '@web3modal/ethereum'
interface Options {
address: string
chainId: string
formatUnits: FetchTokenArgs['formatUnits']
}
const { refetch, isLoading, error, token } = useToken(options)
Hook to read and watch contract
import { useWatchReadContract } from '@web3modal/ethereum'
interface Options {
callback: WatchReadContractResult
listenToBlock: boolean
}
useWatchReadContract(options)
Hook to fetch public address from ens adress
import { useFetchEnsAddress } from '@web3modal/ethereum'
interface Options {
chainId: string
name: string
}
const { refetch, isLoading, error, address } = useFetchEnsAddress(options)
Hook to fetch ens avatar
import { useFetchEnsAvatar } from '@web3modal/ethereum'
interface Options {
chainId: string
addressOrName: string
}
const { refetch, isLoading, error, avatar } = useFetchEnsAvatar(options)
Hook to fetch ens name for public address
import { useFetchEnsName } from '@web3modal/ethereum'
interface Options {
chainId: string
address: string
}
const { refetch, isLoading, error, name } = useFetchEnsName(options)
Hook to get contract address for ens name resolver
import { useFetchEnsResolver } from '@web3modal/ethereum'
interface Options {
chainId: string
name: string
}
const { refetch, isLoading, error, address } = useFetchEnsResolver(options)
Hook to fetch a transaction
import { useFetchTransaction } from '@web3modal/ethereum'
interface Options {
chainId: string
hash: FetchTransactionArgs['hash']
}
const { refetch, isLoading, error, transaction } = useFetchTransaction(options)
Hook to prepare send transaction request
import { usePrepareSendTransaction } from '@web3modal/ethereum'
interface Options {
chainId: string
request: PrepareSendTransactionArgs['request']
signerOrProvider?: PrepareSendTransactionArgs['signerOrProvider']
}
const { refetch, isLoading, error, transaction } = usePrepareSendTransaction(options)
Hook to send transaction
import { useSendTransaction } from '@web3modal/ethereum'
interface Options {
chainId: string
request: SendTransactionArgs['request'] & {
to: `0x${string}`
gasLimit?: Exclude<SendTransactionArgs['request']['gasLimit'], undefined>
}
}
const { refetch, isLoading, error, transaction } = useSendTransaction(options)
Hook to send transaction
import { useWaitForTransaction } from '@web3modal/ethereum'
interface Options {
chainId: string
confirmation?: number
hash?: string
timeout?: number
wait?: WaitForTransactionArgs['wait']
}
const { refetch, isLoading, error, transaction } = useWaitForTransaction(options)
FAQs
#### 🔎 [Examples](https://github.com/WalletConnect/web3modal-examples)
The npm package @web3modal/react receives a total of 2,509 weekly downloads. As such, @web3modal/react popularity was classified as popular.
We found that @web3modal/react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 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
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.