Hi guys. I’m new at solidity and I’m trying to use the push function (line 27) and it gets me this error, somebody Know what i need to do to make it work?
I’m using ^0.6.0 version
Dec 26, 2021, 7:26 PM
google that error message, it calls out exactly what the problem is
Dec 26, 2021, 7:27 PM
Please enter favoriteNumber and name in push
Sorry, now people is not array
Dec 26, 2021, 7:58 PM
This works on my remix.
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
contract SimpleStorage {
struct Person {
uint256 favoriteNumber;
string name;
}
Person[] people;
function addPerson(uint256 _favoriteNumber, string memory _name) public {
Person memory person = Person(_favoriteNumber, _name);
people.push(person);
}
function getPerson(uint _idx) public view returns(Person memory) {
Person storage person = people[_idx];
return person;
}
}
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
contract SimpleStorage {
struct Person {
uint256 favoriteNumber;
string name;
}
Person[] people;
function addPerson(uint256 _favoriteNumber, string memory _name) public {
Person memory person = Person(_favoriteNumber, _name);
people.push(person);
}
function getPerson(uint _idx) public view returns(Person memory) {
Person storage person = people[_idx];
return person;
}
}
Dec 26, 2021, 8:00 PM
People memory newPeople = People({
favoriteNumber:_favoriteNumber,
favoriteNmae: _name
});
people.push(newPeople);
favoriteNumber:_favoriteNumber,
favoriteNmae: _name
});
people.push(newPeople);
Please rename the struct type people as People
So, all code is done except for fee only on sell?
await is used for async function
Dec 26, 2021, 10:58 PM
Every contract call is asynchronous - you are communicating node (even if it’s a JavaScript one for testing purposes), so the calls should be async
Also, I don’t think you need the .call there after balanceOf as it is a read only function
Call should be implicit
Dec 26, 2021, 11:52 PM
Use person.push
Dec 27, 2021, 7:22 AM
Only thing is it’s hard to find them now with 32GB ram, so no VMs for me unless I am on my desktop
Dec 27, 2021, 7:35 AM