Ethereum Smart Contract Programming


Hi, does anybody know in the Dog (array & structs) contract how do you get to display the dogs age, Fillip showed us how to call the dogs name but never how to call the age ? Thank you


Just replace .name with .age.


Mappings assignment

the limitation is it is not operating on any stored information, it’s extremely limited and only really parroting back what is put in and it’s address
If the address has not previously passed it a dog it only responds with nothing (which is lousy error handling at least)

Solution - bring back the array but have protected hash type values?


pragma solidity 0.5.1;

contract DogContract{

function addDog(string memory _name, uint _age) public payable returns (uint);

function getBalance() public view returns (uint);


contract ExternalContract {

DogContract dc = DogContract(0x76A846CD2aC2E028626A3d1f5ddf32d3a468423D);

function addExternalDog(string memory _name, uint _age) public payable returns (uint){
    return dc.addDog.value(msg.value)(_name, _age);

function getExternalBalance() public view returns (uint){
returns dc.getBalance();


I don’t really agree on the first part. But maybe you can clarify what you mean? The issue with the mapping in this video is that we can overwrite our previously added dog.


Thanks for reply f

I think I’m trying to get my head around what this would actually be used for… it can’t be used for more than one dog therefore is less use than the previous array example.
It does have a purpose when the address is used, and it becomes apparent this is used for validating an address for security purposes, but it can only validate one?

Maybe you’ve gone from a simple example to a practical example and I got lost somewhere. I did see the solution and it made sense.


Hi @filip, sorry to bother you again. after watching the video about payable functions, I tried to add a dog using 10 000 wei. The transaction is successful as expected, however, I can see that the value of the transaction is 10 000 wei.

we have put the give back excess condition in the costs modifier though. Is that the log we expected? I get that it is the value that I sent, but as is, the blockchain will record that I spent 10 000 wei on this transaction, won’t it? is it just up to the developers to set the proper events so that if some excess amount is given back, it is recorded?

thanks in advance for your help


Solution to the getbalance exercise:

    function externalGetBalance() public view returns(uint){
        return dcInstance.getBalance();