Playing with drizzle, I am trying to use a getter for an uint variable campaignCounter, that gets incremented by 1 whenever a factory creates a new campaign.

Here is my component's code:

import React, { Component } from "react";

class ReadCounter extends Component {

  state = { dataKey: null};

  componentDidMount() {
    const { drizzle, drizzleState } = this.props;

    const contract = drizzle.contracts.CampaignFactory;

    const dataKey = contract.methods.campaignCounter.cacheCall({from: drizzleState.accounts[0], gas: 3000000});

    this.setState({ dataKey });

  render() {
    const { CampaignFactory } = this.props.drizzleState.contracts;

    const campaignCounter = CampaignFactory.campaignCounter[this.state.dataKey];

    return <p> Number of campaigns {campaignCounter && campaignCounter.value}</p>;

export default ReadCounter;

In the console i get the following error:

index.js:1375 uncaught at _callee at _callee 
 at contractsSaga 
 at takeEvery 
 at callCallContractFn 
 Error: Invalid number of parameters for "campaignCounter". Got 0 expected 1!

I have tried:

const dataKey = contract.methods.campaignCounter.cacheCall({from: drizzleState.accounts[0]});


const dataKey = contract.methods.campaignCounter.cacheCall();

For each case the same error is thrown.

My setup:

Truffle v5.0.18 (core: 5.0.18)
Solidity v0.5.0 (solc-js)
Node v10.16.0
Web3.js v1.0.0-beta.37

Why does it expect a parameter for a getter function that only returns an uint? And what would be the parameter?



pragma solidity ^0.5.0;

contract CampaignFactory {

    address[] public deployedCampaigns;
    uint public campaignCounter;

    function createCampaign(uint minimum) public {

        address newCampaign = address (new Campaign(minimum, msg.sender));

    function getDeployedCampaigns() public view returns(address[] memory) {
        return deployedCampaigns;
  • Show the contract code (Solidity) for the function. Commented Jun 3, 2019 at 21:54
  • Sure - original post edited.
    – Arson
    Commented Jun 3, 2019 at 21:59

2 Answers 2


In smartcontract, method createCampaign(uint minimum) takes one argument as uint input.

But during calling this method, You are not passing any uint argument.

const dataKey = contract.methods.campaignCounter.cacheCall({from: drizzleState.accounts[0], gas: 3000000});,

So maybe your method calling should be like this:

const dataKey = contract.methods.campaignCounter.cacheCall(**uint parameter**, {from: drizzleState.accounts[0], gas: 3000000});
  • I am trying to use a getter for this variable: campaignCounter. It is not the issue with calling createCampaign method - this one works perfectly fine. Since campaignCounter is a public variable, it should have a getter, but it takes no arguments, hence I do not understand the nature of the error.
    – Arson
    Commented Jun 4, 2019 at 6:43

Issue fixed, steps:

const dataKey = contract.methods["campaignCounter"].cacheCall({from: drizzleState.accounts[1], gas: 3000000});

I deleted .json files with contracts

Recompiled and migrated again.

Works perfectly fine.

  • Can you explain why your solution worked? Commented Jul 15, 2022 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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