[英]Accepting parameters in javascript to send to solidity smart contract
Wrote this simple solidity contract where the functions accept a few parameters. 在函数接受一些参数的地方写了这个简单的契约。
function fund(uint _dbIndex, uint _fundedAmount) public {
uint totalAmount = projectWallets[_dbIndex].fundedAmount;
totalAmount += _fundedAmount;
projectWallets[_dbIndex].fundedAmount = totalAmount;
}
after creating this smart contract, i tried connecting the SC to a HTML page with javascript. 创建此智能合约后,我尝试使用javascript将SC连接到HTML页面。 I managed to get a function without parameters to work but couldnt get it to work if theres parameters in the function..
我设法使一个没有参数的函数正常工作,但是如果函数中有参数,则无法正常工作。
<input type="number" min="0" placeholder="Fund Amount" style="color: black;" id="fund">
<button id="fund_project">Fund Project</button>
above is the input and button to send the value into the smart contract. 上面是将值发送到智能合约的输入和按钮。
$('#fund_project').click(function (e) {
e.preventDefault();
log("Calling fund function...");
counter.fund(dbIndex, funds);
});
and this is a segment of the code where i take in the function with parameters. 这是代码中我带有参数的函数的一部分。 How do i get it to work?
我该如何工作?
A callback is a function that is called when the operation is complete. 回调是在操作完成时调用的函数。 You need to use one, eg:
您需要使用一个,例如:
counter.fund(dbIndex, funds, function (err, result) {
if (err) {
console.log('Error: ' + err);
}
else {
console.log(result);
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.