I have the following contract, made extremely simply:

pragma solidity ^0.4.18;

contract Test {
  bool completed;

  function Test() {
    completed = false;

  function setCompleted() public {
    completed = true;

  function getCompleted() public view returns (bool) {
    return completed;

And I am testing it in javascript like so:

var Test = artifacts.require("./Test.sol");

contract('Test Contract', function(accounts) {
  it("should set and get completed", function() {
    var TestContract

    return Test.deployed().then(function(instance) {
      TestContract = instance

      return TestContract.getCompleted.call()
        .then(function(result) {
          console.log(result, 'should be false');
          return TestContract.setCompleted.call()
        .then(function() {
          return TestContract.getCompleted.call()
        }).then(function(result) {
          console.log(result, 'should be true');

Shouldn't the call to the setCompleted function update the contract's variable? Am I missing something?


Calls don't change the contract state over the network, transactions do that.

On another note, you doon't need the function getCompleted, solidity creates a getter function for every public variable automatically

  • How would you call the getter function with web3js? – timothyylim Feb 20 '18 at 20:06
  • TestContract.completed.call() should work – Hari GTT Psicolabis Feb 20 '18 at 20:45

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.