Gas Cost Example – Simple Example for Gas Cost in Ethereum

gasgas-price

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!

Best Answer

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];
  }
}
Related Topic