0

Assume that the following contract has been deployed to Ethereum. Do I have to pay anything if I want to run it?

    contract NameRegistry {
mapping(bytes32 => address) public registryTable;
function claimName(bytes32 name) {
if (msg.value < 10) {
throw;
}
if (registryTable[name] == 0) {
registryTable[name] = msg.sender;
}    }    }

1 Answer 1

1

Every function which changes state of contract (writes/changes variable data) consume gas (ETH). Since registryTable[name] = msg.sender; in your function assigns data to mapping, it will consume gas. Gas is not consumed only when you call view function from external sources or from other view contract, in other words when data in contract is not altered.

4
  • Thank you for the answer! So, to use this contracts I will have to send more than 10 wei in my execution triggering transaction. Then miners will run the contract on their machines and update the state in the blockchain. Is this understanding right?
    – Alex
    Aug 9, 2018 at 17:48
  • You can check ethgasstation.info for the best gas price to fit you. When sending transaction you can enter the gas price which will determine how long it will take for tx to be mined. And yes, you got it right. Just be noted that if your provided gas price is too low it may take forever to be mined, since miners will just skip it over more valuable transaction. Also if you provide too little gas for transaction it will fail too.
    – Maxpeinas
    Aug 9, 2018 at 17:54
  • Thanks again! One more question: can 'name' variable be something like "Alex"? Then my public address will be connected to this name. I'm just trying to understand how this contract works.
    – Alex
    Aug 9, 2018 at 18:03
  • You can create similar mapping as in your example to assign name to address, but it will be only known to this contract, you can't use name instead of address elsewhere.
    – Maxpeinas
    Aug 9, 2018 at 18:07

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.