4

Given a simple address to address mapping as follows:

mapping (address => address) public matches;

Can someone give me an idea of the cost in ether to store something like this in a solidity contract? I understand that there are gas costs associated with every alteration of the blockchain and storage is expensive but I am having trouble finding estimations of what simple storage like a mapping would cost.

The feasibility of my Dapp idea depends on storing mappings from address to address cheaply. Ideally around 1 cent USD or so. If mappings are more expensive are there any workarounds? Thanks.

1 Answer 1

5

In the simplest implementation I can think of:

pragma solidity ^0.4.6;

contract Mapping {
    mapping(address => address) public matches;

    function writeMapping(address addr) {
        matches[addr] = msg.sender;
    }
}
  1. First write 42K gas
  2. Overwrite 27K gas

enter image description here

Gas price in Eth and ETH price in $ both float on markets, so any estimate would be a forecast.

The gas cost operations are knowable and should be consistent (in the example) but are subject to periodic change at the protocol level. That is, if the cost/OP table is adjusted in the future.

Hope it helps.

2
  • Thanks Rob. Any idea where I can find what 42K gas equates to at this moment or perhaps before the price rise? Commented Apr 6, 2017 at 10:55
  • It's a two-step. I see a gas price of 18gwei right here: ethstats.net. Convert to 0.000000018ETH ... so 42K times that. Then off to exchange etc., to convert ETH to USD, etc. Good indication of current cost. Usual disclaimer: Past results are not indicative of future performance ... Commented Apr 6, 2017 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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