truffle 和 ganache 打印账号列表和发送eth

 

打印 ganache环境的账户列表

1
2
3
4
5
6
7
8
9
10
const localhost = "http://127.0.0.1:7545";
const {Web3} = require("web3");
const web3 = new Web3(new Web3.providers.HttpProvider(localhost));
 
web3.eth.getAccounts().then(function (result) {
    console.log("账户列表地址:");
    console.log(result);
}).catch(function (error) {
    console.error(error);
});

  运行

 

 

 

发送eth

1
2
3
4
5
6
7
8
9
let amountToSend = web3.utils.toWei('1', 'ether');
  
web3.eth.sendTransaction({
  from: '0xA61Cc9999B16a1F58E3ABBEDF3392b67dAd896fd',
  to: '0xFD3a265399C04b06C9FBBbc28634dA0cB6215736',
  value:amountToSend,
  gas: '1000000',
  gasPrice:1000000000
});

 运行后

 

 

posted @   apeNote  阅读(7)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示