简体   繁体   English

接受JavaScript中的参数以发送到Solidity智能合约

[英]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.

相关问题 如何从 Javascript 向 Solidity 智能合约 function 输入数据? - How to input data to a solidity smart contract function from Javascript? 使用 javascript 调用 Solidity 智能合约来铸造代币似乎不起作用 - Calling solidity smart contract with javascript to mint token does not seem to work Solidity:在智能合约中填充结构 - Solidity: populating a struct in a smart contract 通过javascript(web3.js)从部署的智能合约中调用特定的solidity函数 - Call specific solidity function from deployed smart contract within react through javascript (web3.js) 智能合约:如何在 React 中获得 Solidity function 的回报? - Smart contract: How to get return of Solidity function in React? 我们可以更新部署在 Hedera 测试网中的 Solidity 智能合约吗? - Can we update solidity smart contract which is deployed in Hedera TestNet? 如何使用安全帽和以太币监控 Solidity 智能合约上的事件? - How to monitor events on an Solidity Smart Contract using hardhat and ethers? 如何运行一个成功的 Solidity 智能合约测试脚本? - How To Run A Successful Solidity Smart Contract Test Script? Solidity:从我的智能合约中显示价值以做出反应的问题 - Solidity : Problem to display value from my smart contract to react 坚固性0.4.6中使用send()函数时,合同抛出无效地址 - Contract throws Invalid address when using send() function in solidity 0.4.6
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM