我正在使用 web3 CDN,并且我已经部署了带有两个变量的合同。例子:
pragma solidity ^0.5.0;
contract Sweet() {
address public owner;
uint256 sweets;
uint256 shops;
constructor(uint256 _sweets, uint256 _shops){
owner = msg.sender;
sweets = _sweet;
shops = _shops;
}
function setSweetAndShop(uint256 _sweets, uint256 _shops) public {
sweets = _sweets;
shops = _shops;
}
}
部署此示例代码后,在混音中一切正常。之后,我创建了一个示例 DAPP。
async function change(){
var web3 = await new Web3(window.ethereum);
var account = await web3.eth.getAccounts();
var abi = [];
var contract = "0x000000000.........";
var token = new web3.eth.Contract(abi, contract);
try{
token.methods.setSweetAndShop(10, 20).call({
from: account[0],
gas: 800000
})
.then(function(error, result) {
if (!error){
console.log(result);
}else{
console.log(error); // This part is returning an error g{} , no data inside.
}
})
}catch(error){
console.log(error)
}
}