1

Contract:

contract owned {
    function owned() public { owner = msg.sender; }
    address owner;

    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }
}

contract TestcontractCrowdSale is owned {
    uint public tokens_total = 0;

    struct holder {
        uint tokens_bonus_balance;
        uint tokens_all_balance;
        bool tokens_bonus_canspent;
        uint ethers_crowdfunded;
        uint list_pointer;
    }

    mapping (address => holder) public holders;
    address[] public holdersList;

    mapping (address => mapping (address => uint256)) public allowed;

    function checkIsHolder(address holderAddress) public constant returns (bool isIndeed) {
        if(holdersList.length == 0) return false;
        return (holdersList[holders[holderAddress].list_pointer] == holderAddress);
    }

    function getHoldersCount() public constant returns(uint count) {
        return holdersList.length;
    }

    function newHolder(address holderAddress) public returns(bool success) {
        if (!checkIsHolder(holderAddress)) {
            /*holders[holderAddress] = holder({
                tokens_bonus_balance: 0, 
                tokens_all_balance: 0,
                tokens_bonus_canspent : false,
                ethers_crowdfunded : 0,
                list_pointer : holdersList.push(holderAddress) - 1 
            });*/
            holders[holderAddress].list_pointer = holdersList.push(holderAddress) - 1;
        }
        return true;
    }

    function balanceOf(address tokenOwner) public view returns (uint balance) {
        return holders[tokenOwner].tokens_all_balance;
    }

    function preprint(address _for, uint tokens) onlyOwner public returns (bool printed, address __for, uint bonus_all_tokens) {
        newHolder(_for);
        holders[_for].tokens_all_balance += tokens;
        holders[_for].tokens_bonus_balance += tokens;
        holders[_for].tokens_bonus_canspent = false;
        tokens_total += tokens;
        return (true, _for, holders[_for].tokens_bonus_balance );
    }
}

truffle.cmd develop

truffle(develop)> compile
truffle(develop)> migrate

truffle(develop)> TestcontractCrowdSale.deployed().then((instance) => {contract = instance});

truffle(develop)> contract.preprint.call("0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef","123456",{ from: "0x627306090abaB3A6e1400e9345bC60c78a8BEf57"})
[ true,
  '0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef',
  BigNumber { s: 1, e: 5, c: [ 123456 ] } ]
truffle(develop)> contract.preprint.call("0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef","123456",{ from: "0x627306090abaB3A6e1400e9345bC60c78a8BEf57"})
[ true,
  '0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef',
  BigNumber { s: 1, e: 5, c: [ 123456 ] } ]
truffle(develop)> contract.balanceOf("0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef")
BigNumber { s: 1, e: 0, c: [ 0 ] }
truffle(develop)> contract.tokens_total()
BigNumber { s: 1, e: 0, c: [ 0 ] }
truffle(develop)> contract.tokens_total.call()
BigNumber { s: 1, e: 0, c: [ 0 ] }

But in remix all works OK, preprint function works fine, and i can not understand, why? Contract is same!

enter image description here

That's big problem for me.

1

You are using the web3.js .call method, on contract.preprint.call().

Executes a message call transaction, which is directly executed in the VM of the node, but never mined into the blockchain.

- web3 docs

Changing the command to truffle(develop)> contract.preprint("0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef","123456",{ from: "0x627306090abaB3A6e1400e9345bC60c78a8BEf57"}) should fix it.

| improve this answer | |

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.