1

For example here is my example function in smart contract:

function adoptCreeptomas(uint256 beastQuantity, address referrer
) public payable whenNotPaused {
    msg.sender.transfer(50);
}

And then I try to test this contract:

describe("adopted creeptoma", async function() {
    it('adopted', async function() {
        let instance = await CreeptomaPresale.deployed();

        let pre = convertEther(getBalance(investor));
        await instance.adoptCreeptomas.call(beastQuantity, 0 {from: investor, value: ether(100)});
        let after = convertEther(getBalance(investor));
        console.log("before: " + pre + "--after: " + after);
    });
});

The printing log is: before: 100--after: 100

Here is my getBalance method:

export function getBalance(address) {
    return web3.eth.getBalance(address)
}

I don't know why balance of account doesn't decrease. Please help me.

Thanks

1 Answer 1

4

You are saying call() when you adoptCreeptomas. call() makes it explicitly a read-only, not state-changing, dry-run operation. It is not signed or sent to the network for mining, so the next time you look, nothing has changed.

Have a look over here for detailed explanation. What is the difference between a transaction and a call?

Hope it helps.

3
  • Thanks so much. There is a point that I don't understand. I see that my balance is decreased by a number pushed into contract. for example: {from: investor, value: ether(15)} but not my number in method transfer. for example: msg.sender.transfer(10); So is that means all ether will be consumed by function in contract ? thanks.
    – hqt
    Apr 18, 2018 at 18:18
  • I think because my method will always consume all ether from the input. But I am not sure. If in this case, how can I avoid this so I won't use all user's ether.
    – hqt
    Apr 19, 2018 at 3:33
  • First things first. You should ganache-cli or your own private chain so experimentation doesn't cost anything. The ether will go from the from address to the to address if the transaction is successful. Apr 19, 2018 at 3:55

Your Answer

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

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