本文环境:
区块链版本:以太坊POA联盟链
节点版本: geth 1.9.19
nodejs版本:v10.14.0
操作系统:windows 64
本文介绍以太坊网络进行 ether transfer 的方式和代码。
1. 如果节点保存了发送者的keystore文件;就比较简单:
var Web3= require('web3');
var web3= new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
//节点保存了keystore文件,且节点启动时开放了personal,"--allow-insecure-unlock"
web3.eth.personal.unlockAccount("0xb478FbF668848Ba20F0b6425c021f73d21E91606",'password',0);//注意不能用account[0],直接写地址
web3.eth.getBalance("0xb478FbF668848Ba20F0b6425c021f73d21E91606").then(console.log);
// using the promise
web3.eth.sendTransaction({
from: '0xb478FbF668848Ba20F0b6425c021f73d21E91606',
to: '0x1087e9242B30e10b8725Fe02289aF6fdbB064eF1',
value: '1000'
})
.then(f