truffle 和 ganache 列印賬號列表和傳送eth

apeNote發表於2024-10-02

列印 ganache環境的賬戶列表

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

let amountToSend = web3.utils.toWei('1', 'ether');
 
web3.eth.sendTransaction({
  from: '0xA61Cc9999B16a1F58E3ABBEDF3392b67dAd896fd',
  to: '0xFD3a265399C04b06C9FBBbc28634dA0cB6215736', 
  value:amountToSend,
  gas: '1000000',
  gasPrice:1000000000 
}); 

 執行後

 

相關文章