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://本机IP测试')
}
//充值
try {
await web3.eth.getAccounts((err,res) =>{
let addr = res[0];
web3.eth.sendTransaction({
from: addr,
to: '',//转账地址
value: Web3.utils.toWei(/转账金额/, "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
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。