2

I've gone through with the debugger to make sure msg.sender is my metamask account and that it should be updating.

I'm messing with the 0xBitcoin ERC20 contract.

function myfunction() {
     balances[msg.sender] = balances[msg.sender].add(reward_amount)
     // My contract is 18 decimals but even after converting the amount to "ether"-like
     // units the amount is still 2 digits long. So it's not that the update is too small

     emit Mint(msg.sender, reward_amount, epochCount, challengeNumber
}

Where Mint is defined as

event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);

So in summary my account balance doesn't update and I've checked

1) message.sender value

2) reward_amount is large enough that it should be visible

3) the transaction is going to completion without any errors preventing it

What could be going wrong that I haven't considered?


Here's the entire function. It's basically straight from the 0xBitcoin contract cited above.

function Mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
        bytes32 digest = keccak256(abi.encodePacked(challengeNumber, msg.sender, nonce));

        if (digest != challenge_digest) revert();

        if(uint256(digest) > miningTarget) revert();

        bytes32 solution = solutionForChallenge[challengeNumber];
        solutionForChallenge[challengeNumber] = digest;

        if(solution != 0x0) revert(); // same answer can't be awarded twice

        uint reward_amount = getMiningReward();

        balances[msg.sender] = balances[msg.sender].add(reward_amount);
        tokensMinted = tokensMinted.add(reward_amount);

        lastRewardTo = msg.sender;
        lastRewardAmount = reward_amount;
        lastRewardEthBlockNumber = block.number;

        _startNewMiningEpoch();

        emit Mint(msg.sender, reward_amount, epochCount, challengeNumber);

        return true;
    }
  • "My contract is 18 decimals but even after converting the amount to "ether"-like units the amount is still 2 digits long. So it's not that the update is too small" - where exactly do you do that, what is the original amount and what is the amount after you apply this conversion? – goodvibration Mar 5 '20 at 5:31
  • @goodvibration I used Web3 to convert it from “wei” to “ether”. The amount was like 70 afterward. Wei is 10^18 ether so this just takes the number and divides it by 10^18. I know my contract isn’t technical ether – financial_physician Mar 5 '20 at 6:15
  • What is "afterward" in this context? What value are you passing to function myfunction? How are you executing this function? Please share the relevant web3 code. – goodvibration Mar 5 '20 at 6:17
  • You divide the amount by 10^18 before sending it to the contract??? That sounds grossly wrong. What does "my contract don’t technical ether" mean??? – goodvibration Mar 5 '20 at 6:18
  • @goodvibration I used the debugger to figure out what value was being provided in remix. It was like 78230123901928310293 so I copied that number into a Jupyter Notebook that I've been using to interact with my contract. The function is web3.fromWei(balance_wei, 'ether') where I passed in that large number for balance_wei. While my number doesn't represent wei but rather the currency being mined, the conversion is the same (divide by 10^18). So while I didn't divide the number in the contract, it's clear the number should have been big enough to register on my metamask account – financial_physician Mar 5 '20 at 6:26
1

A reason for wallets to not notice new tokens being minted is that they will only listen for Transfer event.

In the ERC20 specification only Transfer event is defined.

For example OpenZeppelin's implementation generates a Transfer with sender being the null address 0x00000000...00.

emit Transfer(address(0), account, amount);

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.