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}}ā"}
I found an alternative that works for me:
https://ipfs.io/ipfs/QmVAwVKys271P5EQyEfVSxm7BJDKWt42A2gHvNmxLjZMps/
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!
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;
}
}
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
Thank you very much!
It works now!
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)
I used Brave. I switched to Crome and all works fine.
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.
@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!
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.ā
Hey @Haug
Metamask faucet is a bit buggy, i ll recommend you to use this faucet instead :
https://faucet.ropsten.be/
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?