Deploying to Testnet - Discussion

Welcome to the forum discussion for this section. Here you can ask questions or post feedback.

I get the error when request ether from faucet (https://faucet.metamask.io/)

{ā€œerrorā€:"[ethjs-query] while formatting outputs from RPC ā€˜{ā€œvalueā€:{ā€œmessageā€:ā€œInternal errorā€,ā€œcodeā€:-32603}}ā€™"}

2 Likes

I found an alternative that works for me:

https://ipfs.io/ipfs/QmVAwVKys271P5EQyEfVSxm7BJDKWt42A2gHvNmxLjZMps/

2 Likes

Hi Filip @filip ,
I had no problem deploying the contract, but when I tried to add ā€œBobā€, the following error appeared:


I checked the cost is 100 wei and if I still try to do the transaction, it shows ā€œinvalid JSON RPC responseā€

Do you know how I can correct the error?
Thank you very much for your help!

Here is the error message:

I did make sure that the cost is 100 Wei:

Sorry for the slow response. Can you post your code for that function?

Hi Filip, thank you for your reply.
I tried again just now, I managed to deploy the contract successfully, but I was unable to create person, the same error message I posted above ā€œGas estimation failedā€ appreared.
The code is here:

import "./Ownable.sol";
import "./Destroyable.sol";
pragma solidity 0.5.12;

contract HelloWorld is Ownable, Destroyable{

    struct Person {
      uint id;
      string name;
      uint age;
      uint height;
      bool senior;
    }
    
    //storage: things that are stored permanently, as long as the contract lives, e.g. owner, mapping
    //memory: things that are only saved during a function execution, (e.g. name argument in the function createPerson) other variables such as int, bool in function argument are by default in memory
    //stack: local variables of value types, normally less than 256 bits, e.g. uint, bool

    event personCreated(string name, bool senior);
    event personDeleted(string name, bool senior, address deletedBy);
    
    uint public balance;

    modifier costs(uint cost){
        require(msg.value >= cost);
        _;
    }

    mapping (address => Person) private people;
    address[] private creators;
    
    function createPerson(string memory name, uint age, uint height) public payable costs(100 wei) {
      require(age < 150, "Age needs to be below 150");
      require(msg.value >= 1 ether);
      balance += msg.value; 
        //This creates a person
        Person memory newPerson;
        newPerson.name = name;
        newPerson.age = age;
        newPerson.height = height;

        if(age >= 65){
           newPerson.senior = true;
       }
       else{
           newPerson.senior = false;
       }

        insertPerson(newPerson);
        creators.push(msg.sender);
    }
    function insertPerson(Person memory newPerson) private {
        address creator = msg.sender;
        people[creator] = newPerson;
        //compare the hash of people[msg.sender] == newPerson
        assert(
            keccak256(
                abi.encodePacked(
                    people[msg.sender].name,
                    people[msg.sender].age, 
                    people[msg.sender].height, 
                    people[msg.sender].senior
                )
            ) 
            == 
            keccak256(
                abi.encodePacked(
                    newPerson.name, 
                    newPerson.age, 
                    newPerson.height, 
                    newPerson.senior
                )
            )
        );
        emit personCreated(newPerson.name, newPerson.senior);
    }
    function getPerson() public view returns(string memory name, uint age, uint height, bool senior){
        address creator = msg.sender;
        return (people[creator].name, people[creator].age, people[creator].height, people[creator].senior);
    }
    function deletePerson(address creator) public onlyOwner {
        string memory name = people[creator].name;
        bool senior = people[creator].senior;
        
        delete people[creator];
        assert(people[creator].age == 0);
        emit personDeleted(name, senior, owner);
   }
   function getCreator(uint index) public view onlyOwner returns(address){
       return creators[index];
   }
   function withdrawAll() public onlyOwner returns(uint){
       uint toTransfer = balance;
       balance = 0;
       msg.sender.transfer(toTransfer); //can use 'send' instead of 'transfer', but if transaction fails, 'send' will still reset balance to 0, wehreas 'transfer' can revert 
       return toTransfer;
   }

}
1 Like

I can see the issue now. In the createPerson function, on the second line, you have:

  require(msg.value >= 1 ether);

So apart from your cost modifier, you have this require-statement as well, which requires 1 ether in order to continue. So the code always fails with 100 wei. Remove this and redeploy :slight_smile:

3 Likes

Thank you very much!
It works now!

4 Likes

When i go to https://faucet.metamask.io/, i get a new screen after a while with this message.

network

currently on mainnet - please select the correct test network

==============================================
Switches to:

MetaMask Ether Faucet

faucet

address: 0x81b7e08f65bdf5648606c89998a9cc8164397647

balance: ā€¦

Can you help me out?

(Metamask installed and active)

1 Like

I used Brave. I switched to Crome and all works fine.

1 Like

Hi,

I am able to execute the createPerson function with the contract deployed to the testnet. The transaction is successful however the Data is incorrect.

You need to switch the format in which you are viewing the data. You have them all selected to text, but all the event arguments are not strings. The name is a string so that will show correctly. But if you want to view a boolean for example, you need to set it to number and look if it 1 (true) or 0 (false).

The etherscan event viewer is pretty confusing and it can be hard to find the right parameters there. Did you send name and senior status in the event? If so I think you will find the senior bool in data field 4, from the top.

1 Like

@filip Iā€™m sorry if this is the wrong thread to request this, but after completing this course, I havenā€™t received my certificate. Usually it comes in email immediately, but itā€™s been a day or two already. I also tried just going through each lesson and clicking Next Lesson over and over again, and it didnā€™t help. Thank you!

Sorry to hear that. Email [email protected] if you havenā€™t already.

Hey, tried to fund my metamask with ether from https://faucet.metamask.io/, it connect properly, but it does not send when I do request 1 ether from the contract. I dont get any transaction detailes, just the option of donating left over of ethers. In the end I got the reply given below. am I the only one having this issue?

ā€œToo many requests, please try again later.ā€

1 Like

Hey @Haug
Metamask faucet is a bit buggy, i ll recommend you to use this faucet instead :
https://faucet.ropsten.be/

4 Likes

@filip thanks for the amazing lessons.

2 Likes

MetaMask would not transfer the ETH account address or balance to the Remix. I was using Brave, then I tried in Chrome. Any ideas on why the account number and balance does not show in Remix after click Connect in MetaMask?