Web3 recharge notes

Time:2022-1-11

import Web3 from ‘web3’
if(window.ethereum){
window.web3 = new Web3(window.ethereum);
try{

window.ethereum.enable();

}catch(error){

console.error('awdawd')

}
} else if(window.web3){
window.web3 = new Web3(window.web3.currentProvider);
}else{
window. web3 = new Web3. providers. Httpprovider (‘http: / / native IP test ‘)
}

//Recharge
try {

await web3.eth.getAccounts((err,res) =>{
            let addr = res[0];
            web3.eth.sendTransaction({
              from: addr,
              To: '', // transfer address
              value: Web3. utils. To Wei (/ transfer amount /, "Ether")
            }).on('transactionHash', function(hash){
                console.log(hash,'-----hash-----')
            })
            .on('receipt', function(receipt){
              console.log(receipt,'-----receipt-----')
            }).on('confirmation', function(confirmationNumber, receipt){
              console.log(confirmationNumber, receipt,'-----confirmationNumber, receipt-----')
            }).on('error', console.error);
        })
        this.show2 = false
      } catch (error) {
        // User denied account access
      }