我正试图在我的Dapps前端创建一个函数,请求用户使用Ether,我知道我必须使用web3.eth.sendTransaction(),但是我不知道如何正确地实现并在我的Dapp前端调用这个函数,谢谢!
目前的代码是:
$("#button").click(function() {
Raffle.main(function (err, result) {
web3.eth.sendTransaction({from:0x627306090abaB3A6e1400e9345bC60c78a8BEf57 ,to:0x086912faa7f6598d28d80c448c8d1e9dae5a4dee, value:web3.toWei(1, "ether")});
console.log(result);
});发布于 2018-02-06 23:43:37
我发现它可以调用一个函数并发送以太,to是我的合同地址,value是我想发送的金额,data是我发送数据时想要调用的函数的地址。
function mainEnter() {
web3.eth.getAccounts(function(error, result) {
web3.eth.sendTransaction(
{from:web3.eth.accounts[0],
to:"0x943",
value: "1000000000000000000",
data: "0xdf"
}, function(err, transactionHash) {
if (!err)
console.log(transactionHash + " success");
});
});
}发布于 2018-01-31 02:27:50
地址应该是字符串:
web3.eth.sendTransaction({
from: "0x627306090abaB3A6e1400e9345bC60c78a8BEf57",
to: "0x086912faa7f6598d28d80c448c8d1e9dae5a4dee",
value: web3.toWei(1, "ether"),
}, function(err, transactionHash) {
if (err) {
console.log(err);
} else {
console.log(transactionHash);
}
});https://ethereum.stackexchange.com/questions/38034
复制相似问题