1.0.9 • Published 1 year ago
metamask-hook-gambaru v1.0.9
:::::::Example Provider::::::
import { ProvideMetamask } from 'metamask-hook-gambaru'
<div>
<ProvideMetamask>
<Component />
</ProvideMetamask>
</div>
:::::::Example Hook::::::
import { useMetamask } from 'metamask-hook-gambaru'
const {
web3
address,
getAddressMetamask,
chainId,
getChainId,
loading,
chainName,
setChainIdMetamask,
errorAddress,
warningMessage,
notInstalled
}: any = useMetamask()
const handleSignIn = async (e: any) => {
e.preventDefault()
await getAddressMetamask()
}
const handleChain = async (e: any) => {
e.preventDefault()
await getChainId()
}
const handleSetNetwork = async (e: any) => {
e.preventDefault()
await setChainIdMetamask(
'0x61',
'Binance Smart Chain',
'https://assets-cdn.trustwallet.com/blockchains/smartchain/info/logo.png',
'BNB',
'BNB',
18,
'https://data-seed-prebsc-1-s1.binance.org:8545/',
'https://testnet.bscscan.com/'
)
}
<div>
<p><strong>{loading ? 'NoAddress' : address}</strong></p>
<p><strong>{chainId}</strong></p>
<p><strong>{chainName}</strong></p>
<button onClick={handleSignIn}>getAddress</button>
<button onClick={handleChain}>getChainId</button>
<button onClick={handleSetNetwork}>setChaiId</button>
</div>