[Ethereum] How much does it cost to upload a smart contract

contract-deploymentgas-pricepricetestrpctruffle

I'm using a local Ethereum testnet and it seems to me that the price of uploading a smart contract is a bit too high.

This is the code for the smart contract:

contract Transfer {
    address owner;

    function Transfer () {
        owner = msg.sender;
    }

    modifier isOwner ()
    {
        if (owner == msg.sender) {
            _;
        }
        else
        {
            revert();
        }
    }

    function sendEther (address dst) isOwner payable {
        if(msg.value<=0) revert();
        dst.transfer(msg.value);
    }

    function getBalance () constant isOwner returns (uint) {
        return msg.sender.balance;
    }

    function () payable  
    {
        if(msg.value<=0) revert();
        owner.transfer(msg.value);
    }

}

After deploying it with truffle, I've seen that the balance of the account from which that contract has been deployed, has been reduced by 0.045 Ether, which would be something around $15 at today's exchange rate.

I don't know if this is normal, but to me it seems way too expensive.

The gas price in my testnet is 20000000000 and current gas price (seen on https://ethstats.net/) is even higher (35500000000). So, if I'm not wrong, deploying it to the mainnet would be even more expensive!

So, in short, my question is: Is this price normal or am I missing something?

EDIT: Solidity browser says that for this very contract, "Creation: 20435 + 126600", which translates to less than $1… is truffle stealing my Ether somehow?!

Thanks a lot in advance! 🙂

Best Answer

You are missing something.

The amount of gas a transaction requires to submit depends on the amount of processing that miners have to do. A reasonable proxy to this is the amount of input data associated with a transaction.

When submitting a contract you submit the encoded bytecode of the contract. The cost you incurred is significantly more than such a simple contract should incur. Without details of how exactly you submitted the contract, no-one can know if you did something wrong.

35.5 Gwei is the current average gas price. You can specify any gas price you want. Example gas prices are outlined here. It just discerns how quickly your transaction will get mined.

Related Topic