1

I'm Trying to call the apply function on the contract ABI but I'm getting:

TypeError: 'apply' is not a function at :1:1

> myContract
{
  abi: [{
      constant: false,
      inputs: [{...}],
      name: "apply",
      outputs: [],
      payable: false,
      stateMutability: "nonpayable",
      type: "function"
  }, {
      constant: true,
      inputs: [{...}],
      name: "getApplicationID",
      outputs: [{...}],
      payable: false,
      stateMutability: "view",
      type: "function"
  }],
  eth: {},
  at: function(address, callback),
  getData: function(),
  new: function()
}

var abi = [{"constant": false,"inputs":[{"name": "hash","type": "bytes32"}],"name": "apply","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"},{"constant": true,"inputs": [{"name": "email","type": "string"}],"name": "getApplicationID","outputs":[{"name": "","type": "uint256"}],"payable": false,"stateMutability": "view","type": "function"}]
var myContract = web3.eth.contract(abi,"0xcbbfbafedb0eb83016d2a96a4e80d30b20fa3e30");
 myContract.apply("4183f3a48d92d7b874e0e2dc0353e29aee0031b0a174be6f6a2e7a289e9febca");
  • Is this web3.js 1.0.0? If so, I think you might need myContract.methods.apply(...). – user19510 Jan 13 '18 at 16:39
  • > web3.version { api: "0.20.1", ethereum: "0x3f", network: "9876", node: "Geth/v1.7.3-stable/darwin-amd64/go1.9.2", whisper: undefined, getEthereum: function(callback), getNetwork: function(callback), getNode: function(callback), getWhisper: function(callback) } > – www.brunoneves.com Jan 13 '18 at 17:19
0

This should work:

var myContract = web3.eth.contract(abi);


var myContractInstance = myContract.at("0xcbbfbafedb0eb83016d2a96a4e80d30b20fa3e30");


var result = myContractInstance.apply("4183f3a48d92d7b874e0e2dc0353e29aee0031b0a174be6f6a2e7a289e9febca");
console.log(result) 

From web3.eth.contracts

  • When I run on terminal I'm getting: Error: exceeds block gas limit at web3.js:3143:20 at web3.js:6347:15 at web3.js:5081:36 at web3.js:4137:16 at apply (<native code>) at web3.js:4223:16 at <anonymous>:1:14 – www.brunoneves.com Jan 13 '18 at 17:22
  • But when I run on remix.ethereum.org I'm getting invalid address – www.brunoneves.com Jan 13 '18 at 17:25
  • Which network do you use? – Roman Frolov Jan 13 '18 at 17:25
  • 1
    Ethereum Ropsten network – www.brunoneves.com Jan 13 '18 at 17:31
  • 1
    Just FYI, apply is not a constant function. – user19510 Jan 13 '18 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.