@filip hello filip!
I am excited to start learning the Ethereum Smart Contracts.
I am facing one problem right now, which is my payment plan on ivanontech academy.
I thought it is monthly payment plan., but it withdraw all of the 1400 dollars. I am very fine with paying monthly payment plan, but now i have a home monthly payment waiting for me, and it is very big amount for me to pay the academy at one.
I have also contacted the support team, if you could help me to reach out to them, because my home monthly mortgage payment is coming due soon. I am very sorry, I should have know before hand. I was planning on enrolling the academy with monthly payment plan. Can you help me to get my refund back sooner. I will be very appreciate you. thank you teacher.
Hi, @filip
How do you restrict that one address can add multiple key->values?
something like if (address = null) ⌠?
@Frederic_Vandenplas
Thanks for reaching out!
To add validations (restriction), the best way is to use require()
.
so in add multiple key->values function you only need to add
require(address == "the address you want to be create of maps")
@CryptoKhash
Support team will reach to you in less than 24 hours, please wait for them to help you solve that problem
Ok I see now.
Thanks Taha!
Great! Thank you for your help Nielvosloo!
I took the else if example and expanded it. How many generations are they now and when they begin and end???
pragma solidity 0.5.12;
contract ContactData{
struct Person {
uint id;
string name;
uint age;
uint height;
bool GenBoomer;
bool GenXer;
bool GenYer;
bool GenZer;
}
mapping(address => Person) private people;
// Person[] public people;
function createPerson(string memory name, uint age, uint height) public {
address creator = msg.sender;
// creates a person fastest way
// people.push(Person(name, age, height));
// creates a person easier to read but longer
Person memory newPerson;
newPerson.name = name;
newPerson.age = age;
newPerson.height = height;
if (age >= 58){
newPerson.GenBoomer = true;
}
else if(age >= 41){
newPerson.GenXer = true;
}
else if(age >= 39){
newPerson.GenYer = true;
}
else if(age <= 24){
newPerson.GenZer = true;
}
else{
newPerson.GenBoomer = false;
}
people[creator] = newPerson;
}
function getPerson() public view returns(string memory name, uint age, uint height, bool
GenBoomer, bool GenXer, bool GenYer, bool GenZer){
//people[msg.sender];
address creator = msg.sender;
return (people[creator].name, people[creator].age, people[creator].height,
people[creator].GenBoomer, people[creator].GenXer, people[creator].GenYer,
people[creator].GenZer);
}
}
Check this out!
pragma solidity 0.5.12;
contract HelloWorld {
struct Person {
string name;
uint age;
uint height;
}
Person[] public people;
function createPerson(string memory name, uint age, uint height) public {
people.push(Person(name, age, height));
}
}
In your code:
- Line 5: you have mentioned
struct perso
and notstruct Person
- Line 16: you have not declared length of array as a parameter of struct. Hence you are getting the error.
Hope this helps
Hi @Maximus,
Just to add to what @Taha has already explained, you also need to move the createPerson functionâs closing curly bracket to the end of the function (just like Tahaâs done in the code example heâs posted for you. At the moment youâre closing the function body as soon as youâve opened it.
So, you can either omit people.length
(as in Tahaâs example) or include the additional struct property as in the video, and then on the creation of each new person, the value people.length
evaluates to will be assigned to that property.
Just one final thing. Please donât post screen shots. They are difficult to read, and we canât copy and paste your code in order to execute and test it, if we need to. You should format your code before posting it here in the forum. Click on the </> icon in the menu at the top of this forumâs text editor. This will give you 2 sets of 3 back ticks.
```
input your code here
```
If you now input your code between these, you will end up with it nicely formatted. You should always format the code you post, as it is then much clearer and easier to read, and easier for someone else to copy and paste into a text editor for review and execution. It also makes it easier for you to organise your code with the correct spacing and indentation etc. and to spot any errors or copy-and-paste slips.
Hi @keithra1948,
Great idea, and youâve made a good start. Youâve now got the data you need about the different generations and when they begin and end (provided by @Taha) . Also, consider the following:
- Instead of creating lots of separate properties with Boolean values (one for each generation) you can achieve the same functionality with just one property (e.g.
generation
) and use your conditional execution to assign a value to this property based on the generation of each new person e.g.
if (age >= 120){
newPerson.generation = "lost";
}
else if ... // etc.
-
Your final else statement should capture a new person whose
age
fails all of the preceding conditions, and either:
(i) assigns the value of the most recent generation used in your categorisation to the generation property;
*OR (if a previous condition has already accounted for the most recent generation used in your categorisation, and there are still some possible ages which would not be captured by one of the previous conditions)
(ii) assigns a value to the generation property which represents the fact that no generation has been allocated to this person.
At the moment your else statement captures a person between the ages of 25 and 38, but then doesnât âassignâ this person to any generation, which of course shouldnât happen. -
Now that the
creator
address is used as the key in the mapping for each new person instance, theid
property is no longer needed in thePerson
struct.
Enjoying this course!! very productive and excellent explained by Filip.
I want to share an screenshot of how I am adding notes for the code for every key considerations. They are attached a line below the code!
Thatâs great that youâre really enjoying the course, @josephg!
Thatâs also a very good idea to add notes to your code. This will help you to process what the code and key concepts are doing. It should also help you to remember things more easily, and it will provide a useful reference for you as you progress further.
Just one observation:
You are right that we donât use id
as the key in our mapping in this contract. However, there is nothing stopping us from using uint id
, itâs just that we choose to use an address as the key, instead.
Thanks for the feedback!
I finally made it over to the Ethereum Smart Contract Programming 101 course today! Iâm super excited to jump into all the great material the Academy has provided. Have a great day!
Great to have you here @scornkrypto!
And great that youâre so pumped and ready to dive into Solidity
Do check out other posts here in the forum if youâre not sure about something during the course and are looking for further clarification â youâll find lots of further explanations here. But if you canât find the answer youâre looking for then feel free to post your question and weâll do our best to help you out!
Thank you⌠Will do that i the future :
Hello⌠Iâm building off of the HelloWorld contract. Iâm building a Web3.js interface. Now, Iâm trying to call the withdrawAll() function back into my wallet. any tips or suggestions?
Solidity:
function withdrawAll() public onlyOwner returns(uint) {
uint toTransfer = balance;
balance = 0;
msg.sender.transfer(toTransfer);
return toTransfer;
}
Javascript:
document.getElementById('withdrawButton').addEventListener('click', () => {
console.log('withdraw the funds !');
myContract.methods.withdrawAll().call()
.then(function (result) {
console.log(result);
});
});
Since you create a new thread for the same, answered to your question here.
Thanks