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:
- Each time a new contract is instantiated, we have to mine the block for the contract, and then mine any transactions the user makes to the contract. If we only instantiate one contract, however, we only mine the contract deployment once, and then any transactions thereafter, but...
- If we go with the option of storing all info for all users in one contract, is only the "diff" of the contract data (the "array" of all users) stored as a block, or is the entire set of data stored in every block? Or...
- If we go with the option of "contract per user", does it "waste space" if we're storing the entire contract definition multiple times (and is it worth the possibly redundant mining that needs to take place)?
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.)