function send_ether()
{
var seed = document.getElementById("seed).value;
/*seed是否有效?*/
if(!lightwallet.keystore.isSeedValid(seed))
{
document.getElementById("info).innerHTML = "Please enter a valid seed";
return;
}
var password = Math.random().toString();
lightwallet.keystore.createVault({
password: password,
seedPhrase: seed
}, function (err, ks) {
/*以用户密码作为输出,产生的Uint8类型的数组的对称密钥,这个密钥用于加密和解密keystore*/
ks.keyFromPassword(password, function (err, pwDerivedKey) {
if(err)
{
document.getElementById("info).innerHTML = err; }
else
{
ks.generateNewAddress(pwDerivedKey, totalAddresses);
ks.passwordProvider = function (callback) { callback(null, password);
};
/*【注意】为了能在其他PC浏览器能够访问,此处IP要改为UBUNTU所在的GETH环境的IP*/
/*新建HookedWeb3Provider, 参考https://www.npmjs.com/package/hooked-web3-provider*/ /**
var provider = new HookedWeb3Provider({ host: "http://localhost:8545",
transaction_signer: ks*/
var provider = new HookedWeb3Provider({ host: "http://192.168.1.135:8545",
transaction_signer: ks
});
/*以HookedWeb3Provider为对象产生web3,
不同于宠物商店案例的new Web3.providers.HttpProvider('http://localhost:8545');*/
var web3 = new Web3(provider);
var from = document.getElementById("address1).value;
var to = document.getElementById("address2).value;
var value = web3.toWei(document.getElementById("ether).value, "ether);
/*从源地址钱包向目标地址钱包发送value的以太币*/
web3.eth.sendTransaction({
from: from,
to: to,
value: value,
gas: 21000
}, function(error, result){
if(error)
{
document.getElementById("info).innerHTML = error;
}
else
{
document.getElementById("info).innerHTML = "Txn hash: " + result;
}
})
}
});
});
}