Comments (2)
@Katsu1991 In short you can't return a struct but you can return multiple arrays (one for each variable in the struct).
This is an example of the code you'll need to use:
contract People {
Person[] public people;
struct Person {
bytes32 firstName;
bytes32 lastName;
uint age;
}
function addPerson(bytes32 _firstName, bytes32 _lastName, uint _age) returns (bool success) {
Person memory newPerson;
newPerson.firstName = _firstName;
newPerson.lastName = _lastName;
newPerson.age = _age;
people.push(newPerson);
}
function getPeople() constant returns (bytes32[], bytes32[], uint[]){
uint length = people.length;
bytes32[] memory firstNames = new bytes32[](length);
bytes32[] memory lastNames = new bytes32[](length);
uint[] memory ages = new uint[](length);
for (uint i = 0; i < people.length; i++){
Person memory currentPerson;
currentPerson = people[i];
firstNames[i] = currentPerson.firstName;
lastNames[i] = currentPerson.lastName;
ages[i] = currentPerson.age;
}
return (firstNames, lastNames, ages);
}
}
Here is a link to an in depth explanation of the above code:
https://www.youtube.com/watch?v=3-XPBtAfcqo&t=2115s.
from solidity-baby-steps.
@DavidKnott thanks ,I got it.
from solidity-baby-steps.
Related Issues (11)
- 20_value_incrementer.sol has no pragama compiler version specified.
- where is mortal
- Replace kill() by Mortal
- Replace kill() by Mortal HOT 1
- Harmonise compiler versions
- 30_endowment_retriever.sol#L6 should have payable in constructor
- No compiler version specified
- change HOT 1
- Add a license
- Deprecated 'constant' modifier on functions should be 'view' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solidity-baby-steps.