Brave Wallet detection
We recommend that Dapps use a Brave Wallet button and that they treat Brave Wallet like MetaMask.
Compatibility with MetaMask
Since Brave Wallet aims to be compatible with MetaMask's exposed API, we set window.ethereum.isMetaMask to true.
Brave Wallet Provider injection & detection via library
Check out these open-source libraries for off-the-shelf solutions
Synchronous detection
const isBraveWallet = window.ethereum.isBraveWallet
console.log('Brave Wallet: ', isBraveWallet)
Asynchronous detection using web3_clientVersion
const isBraveWallet = await window.ethereum.request({
method: 'web3_clientVersion'
}).then((clientVersion) => {
return clientVersion.split('/')[0] === 'BraveWallet'
})
console.log('Brave Wallet: ', isBraveWallet)
Or:
const isBraveWallet = await window.ethereum.request({
method: 'web3_clientVersion'
}).then((clientVersion) => {
return window.ethereum.isMetaMask && clientVersion.split('/')[0] !== 'MetaMask'
})
console.log('Brave Wallet: ', isBraveWallet)