Ethereum Smart Contract Programming

Do you have metamask installed, running and logged in?

once i switched to send back a change in “send” manner instead of “transfer” it worked.

1 Like

yes it is running, holds eth but not ingects the address into account window

1 Like

ok dosnt matter switched to opera and it finely runned ok.
thanks.

1 Like

Using this contract as the base add the following to get the balance of the external contract in question.

function getExternalBalance() public view returns (uint){
    return dc.getBalance(); //OR address(dc).balance; also works
}
1 Like

Just posting the solution I came up with to Exercise 1 in relation to prevent a Dog being overwritten for the owners public address. I was probably over thinking it as I came from the perspective of having an array of Dogs per address, and you can search for a Dog based on it’s age.

pragma solidity 0.5.1;

contract DogContract {
    struct Dog {
      string name;
      uint age;
    }
    
    Dog[] dogs;
    
    mapping(address => Dog[]) ownerToDogs;
    
    function addDog(string memory _ownerName, uint _age) public {
        dogs.push(Dog(_ownerName, _age));
        ownerToDogs[msg.sender] = dogs;
    }
    
     function getDog(uint searchByAge) public view returns (string memory) {
        Dog[] memory storedDogs = ownerToDogs[msg.sender];
        for (uint i = 0; i < storedDogs.length; i++) {
           Dog memory currentDog = storedDogs[i];
           if (searchByAge == currentDog.age) {
                return currentDog.name;
           }
        }
        return "No dog with this age found!";
       
    }
}
1 Like

Hi folks,

I got a remix/metamask problem here, trying to follow along the lecture about testnet deployment.

Metamask does not inject into remix. The Account field remains empty.
Logged in to Metamask, got some ether in it, tried Ropten and Rinkeby testnet, tried in Chrome and Brave browsers, without success. Someone got an idea? Don’t want to install and try x different browsers.

Thx
Michael

Just to make sure. Are you logged in to metamask and have selected injected web3 in remix?

If that doesn’t work. You can also try to go into metamask settings -> Security & Privacy -> Turn off privacy mode.

1 Like

Turning off privacy mode did the trick. Thank you, Filip.

1 Like

mappings assignment
https://ivanontech.teachable.com/courses/287053/lectures/8617350

I guess, the issue with the “addDog” function is the absence of checking if that address already has some data. In this case it might not make sense to overwrite and revert() might be a rihgt thing to do.

I guess, It also might make sense to return “string storage” in “getDog()” to avoid gas waste on moving data around.

1 Like

error handling + assignment
https://ivanontech.teachable.com/courses/287053/lectures/8617415

Require should be used to validate the age.

require(ownerToDog[msg.sender].age == 0);

Dog memory currentDog = Dog(_name, _age);
ownerToDog[msg.sender] = currentDog;

1 Like

Hi everybody!

I try to get the free ETH thanks to the website https://faucet.metamask.io/
but I don’t know why it doesn’t work:


I press the button “request 1 ether from faucet” but I can see nothing on my wallet:

Is there anybody out there who have an idea to solve this?

Did your metamask window open up when you pressed the request button? You should have to press confirm in metamask in order for the transaction to go through. You can try to go into metamask settings and disable privacy mode.

Hi Filip,

I want to complain about how you show your code on the screen. I am having a hard time reading it since it is SOOOOO SMALLL! I can´t follow you unless I enter full screen mode which made me have to paused everytime I want to try it myself. Thats really unconvinient!!

WHY can´t you make the code bigger like what Ivan did in JS and C++ videos?? Really man, it gets into my nerve so much. I really want to be able to code but you are not HELPING!

ALL of your videos are like this and this is not good service for us all. PLS FIX IT!!

When I clicked on the request button my metamask window opened. Then I disabled the privacy mode as you told me. But there is no ETH.

disable-privacy-mode-on-metamask zero-eth

Try to change your metamask network to ropsten and try again.

Thank you for the feedback. I know that the text is very small is some of the videos in the SC programming course. I have addressed this feedback in all new videos that I upload, both in new courses and in the updated videos I have added and replaced in this course.

Sometimes it’s also hard to fit everything on the screen in tools such as Superblocks and Remix where there is so much more than just the code. By I feel you and I promise you it will get fixed as videos get updated.

I don’t understand why but with rinkeby nothing work


And with ropsten that works

Do you have an idea why?

Probably something wrong with the faucet site.

OK thanks for your answer