I am playing with a private Ethereum blockchain, and I am interested in implementing some smart contracts. However, information is very limited since this is a newer implementation of the blockchain.
Just as an example, say I want a contract that holds information about a person. Is it more efficient to create a new contract for each person, or simply hold information about all users in the same contract?
In pseudo-code, the two options look like this.
Option 1 (instantiate a new contract for each person):
contract = // contract code
ethereum.newContract(contract, userInfo);
Option 2 (hold info of all users in one contract):
contract = {
var users = [];
// other contract code
}
ethereum.newContract(contract, userInfo);
Here's how we can quantify "efficiency" in this case:
Hopefully I was clear in my question, but if not, please let me know. I believe this question is one of "trade offs".
(Re: the tags -- I'm using the golang implementation of Ethereum, and a JavaScript API to interact with it.)
Yes. However, each time you want to add a user you will have to send a transaction for adding a new record to the existing contract.
Blocks consist of transactions. Each time you add a user, you will have to create a transaction for the corresponding function call. However, you will only have to do this once and not the data will not be redundantly copied to future blocks.
Yes.
From the way your question is structured, it seems you should read up again on the difference between transactions and blocks.
A single contract for all users should be sufficient, given that your user objects are not too large.
From the code above, suggest using a map
which will allow more efficient fetching of user records than an array. Key the records by any string, such as first+last name.
mapping(string => user_struct) public users;