4

I'm totally new when it comes to Ethereum and have a few questions when it comes to gas costs (I know of the 1.0 table but it doesn't really help me to find out what I need)

If I simply want to create a smart contract that stores a list of names (8 byte each name) and an according list of Ethereum adresses, each connected to a certain name. How much gas would it cost to

  1. Create such a smart contract (first with only 1 name + address)

  2. Add a new new name+address in this list

  3. Finding the name to an according address and retrieve the name from the blockchain

I hope the provided information is enough to give an estimate gas cost for these actions. Would be very grateful for some help with this!

2

I agree with gatb27 about using Browser Solidity to get a feel for it.

Here's a little toy that does approximately what you described. Paste the code, click create, and then set a name.

setName() expects you to provide a quoted address and hex string like this (copy/paste should work):

"0x35ef07393b57464e93deb59175ff72e6499450cf","0x1"

You can get the set values back with the other function and just the address.

pragma solidity ^0.4.6;

contract PlayWithGas {

  mapping(address => bytes32) names;

  function setName(address userAddress, bytes32 name) returns(bool success) {
    names[userAddress] = name;
    return true;
  }

  function getName(address userAddress) returns(bytes32 name) {
    return names[userAddress];
  }
}
2

I think that the best way to learn something about the gas consumption is practicing with the solidity online compiler.

You can write your code on the left panel, then on the right you'll find some buttons easy to understand. The online compiler gives you an estimate of the gas consumption both for the deployment of the contract and for the functions.

At this page by ethereumoxford you can find a tutorial that shows you also the gas consumption in the online compiler :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.