0

The contract I am working on is failing when trying to send a transaction with MetaMask from an address thats not the owner. I have tried multiple times and also added huge amounts of gas. Even with the huge gas, it does not work with the non owner address. The error message on Etherscan is "Sorry, we are unable to locate this Transaction Hash". It works with the owners address. It also works on Remix Javascript VM from other addresses. What is causing it to fail on MetaMask from an address other then the owners?

I am calling the "update" function. I left out SafeMath library in the example below to make things easier to see.

I tried a few other accounts out and it worked. For some reason, the one account won't budge.

 pragma solidity ^0.4.24;

    // Allows users to "heart" (like) a DAPP by dapp id
    // 1 Like = XXXXX eth will be set on front end of site
    // 50% of each transaction gets sent to the last liker

    contract dappHearts {

        using SafeMath for uint256;

        // set contract owner
        address public contractOwner;
        // set last address transacted
        address public lastAddress;

        // only contract owner
        modifier onlyContractOwner {
            require(msg.sender == contractOwner);
            _;
        }

        // set constructor
        constructor() public {
            contractOwner = msg.sender;
        }

        // withdraw funds to contract creator
        function withdraw() public onlyContractOwner {
            contractOwner.transfer(address(this).balance);
        }

        // map dapp ids with heart totals
        mapping(uint256 => uint256) public totals;

        // update heart count
        function update(uint256 dapp_id) public payable {
            require(msg.value > 1900000000000000);
            totals[dapp_id] = totals[dapp_id] + msg.value;
            // send 50% of the money to the last person
            lastAddress.transfer(msg.value.div(2));
            lastAddress = msg.sender;
        }

        // get total hearts by id
        function getTotalHeartsByDappId(uint256 dapp_id) public view returns(uint256) {
            return totals[dapp_id];
        }

        // get contract balance
        function getBalance() public view returns(uint256){
            return address(this).balance;
        }

    }
1

See if that address is able to send a normal transaction. For instance, it may be that your account nonce has got out of sync, or that the account contains less value than you think.

PS Be aware that transfer will throw an error on failure and abort your update, and whether this fails is in the hands of your lastAddress, which could be a contract. Also, your contract seems to want to send the first payout to the address 0x0, which is probably not what you want.

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.