1

I have two contracts, Token and Voter. I'd like to initiate a DAO, such that first someone initializes a token and distributes some shares to whoever it wants.

In Vote contract, only the token-holders are allowed to vote for something (e.g. certain project should receive some funding).

I'm using remix IDE to compile my contracts, but I don't know how Vote contract is supposed to call Vote contract. Therefore, I've put both in the same place.

Token contract stores an array of addresses belonging to whoever receives the tokens. Now, Vote contract should be able to get the array and check if the person who votes and calls Vote contract is in the array (kept by Token).

contract Token {
address [] publick voters;
//... some functions that assings values to the array...
}

contract Vote{
 // people first vote... Assume they've already done that.
 //Below we want to check which of them have tokens.

Token token= new Token();
address valid_voters = token.voters();// Here an error shows up

// then check
}

Question 1: How an array variable in one contract can be accessed by the other one? (e.g. voters in the above example)

Question 2: In remix how one contract can call the other one? and where to put the first one? (e.g. where to put Token contract and how Vote can call it)?

1

The compilation error gives the first clue:

Wrong argument count for function call: 0 arguments given but expected 1

The reason that the call expects an argument is that voters is an array, and you must provide the index of the element that you want to look up. You cannot copy the full array.

Here is a working example of looking up the first selement in the voters array:

pragma solidity ^0.4.15;

contract Token {
    address [] public voters;

    function Token(address first_voter) {
        voters.push(first_voter);
    }
}

contract Vote{
     // people first vote... Assume they've already done that.
     //Below we want to check which of them have tokens.

    function check_first_voter() returns (address) {
        Token token = new Token(0x123);
        address valid_voter = token.voters(0);  // Retrieve first voter

        // then check
        assert(valid_voter == 0x123);
        // Success!
        return valid_voter;
    }
}
  • thanks for the answer. Also, could you please give me some clue about the second question? – user153465 Aug 16 '17 at 19:39
  • One option is to put them all in the same file (as above). Alternatively, you can put Token in a separate file called "Token.sol" and then add this line to the top of the "Vote.sol" file: import "./Token.sol"; – carver Aug 16 '17 at 20:06

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.