Hi @FrankB,
Good question…
Apologies for not having got back to you sooner.
Take a look at this link. I think it answers your question, but let us know if you have any further ones.
Hi @FrankB,
Good question…
Apologies for not having got back to you sooner.
Take a look at this link. I think it answers your question, but let us know if you have any further ones.
So as far as I can tell, it is the case that the revert-function makes the difference. That’s what I thought. Thank you so much for the clarification.
Yes, that’s my understanding as well
require()
is performing error handling i.e.
…and not performing conditional execution with different possibile paths to continue on within the function i.e.
difficulty locating the error in this build…pretty much following the recipe from Filipe, please assist
****resolved, blocks messed up, fixed curly bracket
somehow I ran out of funds on multiple accounts so I am not able to properly test these contracts. How do I refill?
****simple refress of Remix
I keep getting this gas limit error when testing contract…there is 100 ether in wallet…not sure what is going on here
***Resolved, simple refresh of Remix (and reading of other queries in the chat…brutha gotta read and not perpetuate the ‘you wanna hide something, you write it in a book’)
Hello filip
I get this error message on my code below. I think maybe i need to alter something in the version?
insertPerson (newPerson);
creators.push(msg.sender);
}
function insertPerson(Person memory newPerson) public{
address creator = msg.sender;
people [creator] = newPerson;
}
error message…'This type is only supported in ABIE ncoder V2 to enable the feature.
The error message you are seeing is a result of the fact that Solidity does not yet support two levels of dynamic arrays, which a people[]
would be.
If you could post the full code, it will be more helpful.
The error is telling you to add an additional line to the top of your code:
pragma experimental ABIEncoderV2;
Hello Taha
Thanks for reaching out, much appreciated! Below, is my full code. I did add the ‘experimental…’ line to the top of my code, but it is error messaging me as something not declared on my ‘address [] private creators;’ line.
pragma solidity 0.6.6;
contract HelloWorld{
struct Person{
string name;
uint age;
uint height;
bool senior;
}
address public owner;
constructor() public{
owner = msg.sender;
}
mapping(address => Person) private people;
address [] private creators;
function createPerson(string memory name, uint age, uint height, bool)public{
address creator = msg.sender;
//This creates a person and their credentials//
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) public{
address creator = msg.sender;
people [creator] = newPerson;
}
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{
require (msg.sender == owner);
delete people[creator];
}
function getCreator(uint index) public view returns(address){
require (msg.sender == owner);
return creators [index];
}
}
Thanks
@NetworkP
Try this:
pragma solidity 0.6.6;
//Add this below line extra
pragma experimental ABIEncoderV2;
contract HelloWorld{
struct Person{
string name;
uint age;
uint height;
bool senior;
}
address public owner;
constructor() public{
owner = msg.sender;
}
mapping(address => Person) private people;
address [] private creators;
function createPerson(string memory name, uint age, uint height, bool)public{
address creator = msg.sender;
//This creates a person and their credentials//
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) public{
address creator = msg.sender;
people [creator] = newPerson;
}
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{
require (msg.sender == owner);
delete people[creator];
}
function getCreator(uint index) public view returns(address){
require (msg.sender == owner);
return creators [index];
}
}
Hi Taha
Thanks, i have tried the above suggestion but still no luck so far. I’ll try and reach out to Filip. I am aware that Solidity in it’s current state can be very temperamental.
thanks again.
@NetworkP
No worries! I am the new mentor for this forum
The solution works fine for me.
Would be best if you could share the console error or screenshot of the error.
Thanks
Hi Taha
That’s ok, i am sure you are doing a great job. Filip agrees with you that the solution also works for him, so very strange! I shall try again tho. Perseverance when it comes to coding haha!!
I just found the problem!!
I had an undeclared variable right under the… function createPerson(string memory name, uint age, uint height, bool)public{ which was -
address creator = msg.sender
Thanks for helping out.
So I’ve run into different scenario. After trying to deletePerson(using different address), require() does not throw any error. But also does not delete, which is good. I’m using the same compiler 0.5.12?
status 0x1 Transaction mined and execution succeed
Does it mean they changed how require() works - it’s supposed to throw error, right?
So even if I’m on the same compiler still the code might have different results?
No, the require()
has not changed. There might be something in the contract which is not deleting the person details
If you want to keep your self updated with changes in solidity.
Check out: https://github.com/ethereum/solidity/releases
Whether you are using same or different compiler the result should be same, what changes is the syntax.
@filip I have some difficulty understanding the question 3(quiz).What does the question mean.
Hi @Marcus_Tang,
Q3: Which of the two cases will consume all of the remaining gas in a function call: assert(false)
or require(false)
?
Remaining gas refers to the difference between a higher gas limit set for the transaction by the sender, and a lower actual gas cost of the transaction being completed.
The actual gas cost of completing a transaction
= transaction cost + execution cost
Let’s consider three different scenarios when calling a function which has both a require statement and an assert statement.
I hope that clarifies what the question is about. Let us know if you are still unsure about anything.
Hi, I dont know if this question should be here or not, but I’m a little confused about the balance of a contract and the balance of an address. So far, we have seen in the course that a contract may have a balance or not, and the functions within a contract may have a cost or not, but also I know from previous experiences that a “user” or an “address” may also have a balance. So, what is the difference between the balance of a contract and the balance of a user?? or is it that in Ethereum network all users (wallets for that matter) are really smart contracts that have a balance associated with them??
sorry for the primitive English, I’m not a native speaker.
Here is an explanation about balances and how they work.
In the Ethereum network, both smart contracts and ‘private users’ can have balances.
It is indeed better to say that, in the Ethereum network, all the addresses can have a balance.
There is no difference between the address of a contract and the address of a user.
You can send Ether to both of them.
Now let’s assume that you have a contract and this contract handles the balances of multiple users.
Contract A has the balances of user Javier and Dani.
The contract A balance will be the sum of Javier balance deposited in the contract and Dani balance deposited in the contract.
Javier deposits > 1 ether;
Dani deposit > 1 ether;
Contract balance > 2 ether;
The contract itself will have a mapping inside that tells how much the users (you and me) deposited therefore we will be able to withdraw our balances at any time.
Code example:
pragma solidity ^0.5.0;
contract TestingBalances {
mapping (address => uint256) public userBalances;
function deposit () public payable {
userBalances[msg.sender] += msg.value;
}
}
I hope I’ve answered your question. If you have any doubt just let me know.
Cheers,
Dani
Hi @filip, maybe a basic question here:
Why can’t (or shouldn’t) we assign the owner address outside the constructor such as:
address public owner;
owner = msg.sender;
Could other function modify the value of owner and thus mess with the funcitonality? Thank you