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 }); |
运行后
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步