1

Here I am having an issue where the values are not appearing to function correctly in the Remix IDE browser.

I am trying to have a buyer where they can transfer funds to each other, and the seller can add a description and retrieve the description.

The issue I am finding is when I execute the at the address I can't appear to get the amount from the Buyers contract. The only thing that happens when I click on getAmount it executes but returns nothing.

Any help would be appreciated.

Below is the code I entered into Remix:

 pragma solidity ^0.4.17;

contract Buyer {
        //event LogDescription(address sender, uint amount);
        uint  amount;
        mapping (address => uint) balances;

    function send(address receiver, uint amount) {
        if (balances[msg.sender] < amount) return;
            //if (amount < 10 ether){
                balances[msg.sender] -= amount;
                balances[receiver] += amount;
                //LogDescription(receiver, amount);
            //}
    }

   function getAmount() returns(uint) {
        return(amount);
    }

}

    contract Seller{
        string description;

        Buyer bartscontract;

        function SetDescription(string _description) public {
            description = _description;
            //LogDescription(msg.sender, msg.value, description);
        }
        function getDescription() constant public returns(string) {
            return description;
        }




    }

Here are some screenshots for send and receive ether for further analysis. Below is for Sending 1 Ether to the address: enter image description here

Below is for trying to get or view ether sent to the specified address. enter image description here

2

Your function getAmount do not modify the storage so you can mark as a view

function getAmount() public view returns (uint) {
    return(amount);
}

Remix will create a call when you use the function getAmount.

See this question: What is the difference between a transaction and a call? to understand the difference between a transaction and a call.

  • 1
    Indeed you need the view modifier. I prefer using external/internal over public. – Nico Vergauwen Aug 22 '18 at 21:44
1

The other question I have here is why no value is given and the console just responds back with a call to Buyer.getAmount()? Then no value is actually given back. Is this an error or glitch?

  • 1
    If you have a different question, you can ask it by clicking Ask Question. – Achala Dissanayake Aug 24 '18 at 13:17

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.