react-binance-wallet
v1.0.5
Published
A library helps client connect to binance wallet via extension like Metamask, Binance Chain
Downloads
93
Readme
React Binance Wallet
A library helps the client connect to wallet extensions like Metamask, Binance Chain. This project based on source code of use-wallet
Install
npm install --save react-binance-wallet
yarn add react-binance-wallet
Usage
index
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import { WalletProvider } from 'react-connect-wallet'
ReactDOM.render(<WalletProvider><App /></WalletProvider>, document.getElementById('root'))
App
import React from 'react'
import {useWallet} from 'react-connect-wallet'
const App = () => {
const { account, connect, reset, status, error, balance, chainId } = useWallet()
return (
<div>
<h1>Binance Chain Connector</h1>
{status === 'disconnected' ? (
<>
<button style={{ display: 'block', marginBottom: 16 }} onClick={() => connect('injected')}>Connect Metamask</button>
<button style={{ display: 'block' }} onClick={() => connect('bsc')}>Connect Binance Chain Wallet</button>
</>
) : (
<button onClick={() => reset()}>Disconnect</button>
)}
{ error?.message }
{ chainId != null && <p>chainId: {chainId}</p> }
{account && <p>Connected as {account}</p>}
{Number(balance) >= 0 && <p>{balance}</p>}
</div>
)
}
export default App
License
MIT © andoanwkm