小编Bli*_*liz的帖子

智能合约方法不是web3中的功能

我正在尝试遵循 web3 上的旧教程,但收到错误,我认为这是由于 Solidity 更新所致。我有如下所示的代码

var express = require("express"),
    Web3 = require("web3"),
    web3;    
if (typeof web3 !== 'undefined') {
  web3 = new Web3(web3.currentProvider);
} else {
  // set the provider you want from Web3.providers
  web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}

web3.eth.defaultAccount = web3.eth.accounts[0];

//define contract variable using ABI from compiled Remix tab.
var myContract = new web3.eth.Contract([abi_data]);

myContract.options.address = 'contract_address';

myContract.methods.totalSupply(function(err,res){
    if(!err){
        console.log(res);
    } else {
        console.log(err);
    }
})
Run Code Online (Sandbox Code Playgroud)

其中abi_data是我的合约的abi数据,contract_address是我的合约在Roptsen测试网络中的实际地址,其中totalSupply()是Ropsten测试网络上我的solidity智能合约中的方法,该方法返回合约中引用的代币的总供应量。当测试它以node app.js查看是否正确记录时,返回此错误......

/home/ubuntu/workspace/node_modules/web3-eth-contract/src/index.js:693
    throw errors.InvalidNumberOfParams(args.length, this.method.inputs.length, this.method.name); …
Run Code Online (Sandbox Code Playgroud)

javascript ethereum solidity web3js

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

ethereum ×1

javascript ×1

solidity ×1

web3js ×1