2

Let say I am building a contract which works like a coins/mark point system. I know that when we deploy the contract we need ether. And the transaction will happen which then needs gas for the fee. The gas will be extracted from the ether that the account has right?

The gas is said to be consistent but the number of transaction cannot be predicted. It can be few or huge so how we calculate the ether we need in first place? (I am asking this in case you build an app then release to customer, how you should set up the ether amount and make sure later it not runs out)

Anyone with experience in DApp development out there please help explains how should we allocate ether in first place? And what to do when the ether runs out?

Many thanks

5

It sounds like you have a few fundamental things you're getting confused about with contracts and ether: Firstly, you as a human (or company) owns an Ethereum address which you can use to transfer ether into and out of (your wallet). When you deploy a contract, that action is a transaction in the Ethereum blockchain, and so has to come from some Ethereum address. So, you sign it with your wallet address, and the Ethereum virtual machine creates a brand new address (separate from your own wallet address) for the new contract.

Anyone can send ether to a contract. But getting ether back out is dependent on the code of the contract itself. You need to pick how that's going to work as you develop it.

So, to answer your questions:

The gas [to deploy the contract] will be extracted from the ether that the account has right?

The account that's deploying the contract (your wallet) must have enough ether in it to pay for the gas to create the contract, yes. The newly-created contract will be created with no ether in it (unless the code of the contract does something that transfers ether in).

The gas is said to be consistent but the number of transaction cannot be predicted. It can be few or huge so how we calculate the ether we need in first place?

The amount of gas needed to create a new Contract depends on the code complexity of the Contract itself. You can use the estimateGas() function in web3 to calculate that from the compiled bytecode of your contract before you deploy it (more details).

How you should set up the ether amount and make sure later it not runs out

Both your own personal wallet and any deployed contract can receive ether paid to it. So, if your deployed contract needs to send ether to someone, and it runs out, you can send more to it at a later time. However, it's possible that a contract, once deployed, will not ever need any ether, since it doesn't pay for the gas needed to trigger its methods. A transaction needs to be crafted to call functions on that contract, and that calling function has to come from a human-owned contract, and the human-owned contract pays for the gas of the transaction.

1

The gas will be extracted from the ether that the account has right?

  1. To deploy a contract you need ether in the account that will deploy the contract.

  2. Then every accounts who will interact with your contract will pay the gas. Actually the contract ( and the contract owner ) cannot pay the fees for the user.

But with the incoming release of Metropolis and the account abstraction, smart contracts will be able to pay for fees.

This means actually you do not have to worry about filling your contract with ether since you can't pay the gas for transactions made by other accounts

So the answer of how to calculate the ether we need in first place is actually hard to answer since no contract have done it yet.

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.