When I send transactions to my contract, the wallet tells me that the gas runs out, so how can I specify the gas amount when deploy a new contract?
[Ethereum] How to specify the gas when deploying a new contract in Mist
contract-deploymentethereum-wallet-dappgasmist
Related Solutions
I do not believe it is possible from the UI that the mist wallet provides. You will need to go commandline and use the geth tool. Then you can just unlock your account and perform a transaction and define the amount of gas you want to send.
RPC doc related to function sendtransaction : https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sendtransaction
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.
Best Answer
UPDATE Apr 2 2017
As pointed out by @jeff in the comment below:
Thanks @jeff!
Assuming Ethereum Wallet
I'm assuming the "wallet" in your question refers to Ethereum Wallet (Mist) as your original question did not specify "Mist".
Q: How to specify the gas when deploy a new contract in Mist?
A: When you deploy a contract in Mist (Contracts -> Deploy New Contract), you can change the Fee in the screen. This represents the gas x the estimated gas price as shown in the screen below:
Q: When I send transactions to my contract, the wallet tells me that the gas runs out, so how can I specify the gas amount when deploy a new contract?
A: You cannot specify the maximum gas in the standard Mist interface. Mist seems to try to estimate the gas required, and adds on 100,000 units of gas on top of it's estimate. In the screen below, the estimate is 13,250 gas. Mist specifies the maximum of 113,250 gas:
If you are using
geth
If you are using
geth
, from 2 mapped structs with an address array - push not working:To specify gas when creating the contract:
To specify gas when sending a transaction to your contract:
If you created your contract in Mist and want to send a transaction via
geth
In this section, I've deployed the following code in Mist on Testnet. You can replicate this example on Testnet using the address and information below:
To then get the contract details and use it in
geth
:Get the address Mist deployed your contract to. To do this, click on your contract in Mist and copy the address. In
geth
, assign the address to a variable:Get the JSON Application Binary Interface (ABI). To do this, click on your contract in Mist, click on Show Interface. In
geth
, assign this string to a variable:Create a variable that points to your contract address with the ABI functions exposed by typing the following command in
geth
:You can check that you have assigned your variables correctly by typing the following command in
geth
:You can send a transaction to call the
setNumber()
function using the following command ingeth
:"0xc8eeba52b5970c93e8d8be91632548b1d6400b74bd6dbbc7017e08bcc0b15648"
You can check the status of your transaction using the following command in
geth
:You can call the
getNumber()
function ingeth
using the following command: