在 javascript 中接受参数以发送到 solidity 智能合约

问题描述 投票:0回答:1

写了这个简单的 solidity 合约,其中函数接受一些参数。

function fund(uint _dbIndex, uint _fundedAmount) public {
    uint totalAmount = projectWallets[_dbIndex].fundedAmount;
    totalAmount += _fundedAmount;
    projectWallets[_dbIndex].fundedAmount = totalAmount;
}

创建此智能合约后,我尝试使用 JavaScript 将 SC 连接到 HTML 页面。我设法让一个没有参数的函数工作但如果函数中有参数就无法工作..

<input type="number" min="0" placeholder="Fund Amount" style="color: black;" id="fund">
<button id="fund_project">Fund Project</button>

上面是将值发送到智能合约的输入和按钮。

$('#fund_project').click(function (e) {
  e.preventDefault();

  log("Calling fund function...");

  counter.fund(dbIndex, funds);
});

这是一段代码,我在其中接收带参数的函数。我如何让它工作?

javascript solidity smartcontracts web3js
1个回答
0
投票

回调是在操作完成时调用的函数。你需要使用一个,例如:

counter.fund(dbIndex, funds, function (err, result) {
  if (err) {
    console.log('Error: ' + err);
  }
  else {
    console.log(result);
  }
);
© www.soinside.com 2019 - 2024. All rights reserved.