Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

connecting to user wallet using metamask javascript

//metamask enject ethereum object in browser so you can easily connect.
//this is pure js way you can use ethers.js and web3.js in react.Thanks
let accounts;
const enableEth= async()=> {
accounts= await window.ethereum.request({method:'eth_requestAccounts'})
 .catch((err)=> {
 //error handling
  console.log(err.code) //errorcode 4001 user reject request
})
  console.log(accounts); //["your connected wallet"]
}
Source by # #
 
PREVIOUS NEXT
Tagged: #connecting #user #wallet #metamask #javascript
ADD COMMENT
Topic
Name
9+7 =