2

I'm currently doing some tests with Solidity programming language and EVM. I want to create application where people could make a personal accounts and make some business logic then. But I'm afraid of creating account gas price. Now I have very simple Account contract:

contract Account {
    string name;
    string secName;
    uint balance;

    function Account(string name, string secName) {
        name = name;
        secName = secName;
        balance = 1;
    }
}

Also I have function to create new account in other Manager contract

function createAccount(string name, string secName) isCreator {
        Account account = new Account(name, secName);
        accounts.push(account);
    }

Calling this function cost 127909 gas and now It's around 0.14$ (5 gwei for gas). Seems to be a little bit expensive for creating account with only two text fields.

So the questions is: probably ethereum blockchain is not good solution for Dapp like that or It's possible to decrease amount of gas for creating new account transaction?

1 Answers1

2

Creating a separate contract for each account is probably overkill. Each new account will cost gas for the (identical!) code of the new contract, plus the smaller cost of a transaction. Ethereum may be meant for this, but not done in this way.

You may be able to use structs for the same purpose. For example:

struct Account {
        string name;
        string secName;
        uint balance;
}

Account[] accounts;

function createAccount(string name, string secName) isCreator {
    accounts.push(Account(name, secName, 1));
}

This will likely provide whatever you need, much easier and simpler. You can also look into libraries.

See here for my answer elsewhere on this kind of subject.

Matthew Schmidt
  • 7,290
  • 1
  • 24
  • 35