From what I've read of the Ethereum white paper, it seems that the system is designed to charge you some GASPRICE per instruction in a smart contract's code.

Given this, it seems that there would be some premium placed both on efficient code, and on accurate STARTGAS estimates for existing contracts.

Does there exist some part of the Ethereum ecosystem that:

  1. allows you to chain some contracts together via some kind of import-style syntax

  2. allows you to see estimates of STARTGAS for an existing smart contract

and, most importantly,

  1. (effectively) validates that STARTGAS amount so that you're certain that the contract that you're using is accurately pricing its instruction set?

Relatedly, is there any part of the Ethereum ecosystem that looks to measure and improve the efficiency of existing contract code? It seems like, if you are effectively paying per computational resource used, there would be a big market available in finding more efficiencies.

  • I'm not sure what you're asking in your third question. A contract doesn't "price" its instruction set. The amount of gas used by a transaction is deterministic based on the code and a set of fixed prices. If a particular miner lied about how much gas was consumed by a transaction, other nodes would deem the resulting block invalid and reject it.
    – user19510
    Commented Feb 15, 2018 at 7:48
  • Is it not the case that a person creating a contract is effectively pricing their instruction set by deciding on a STARTGAS/GASPRICE amount, which you could think of as an upper-bound? Commented Feb 15, 2018 at 22:27
  • Each transaction specifies a gas limit and gas price, which means that if you call a function in a smart contract, you pick what gas limit and gas price you want to use. The person creating the contract only specifies the gas limit and gas price for the transaction that creates the contract. (But they're the ones paying it then.) Note that neither the gas limit nor the gas price affects how much gas is used, just how much gas the transactor is willing to pay for and what per-unit price they'll pay.
    – user19510
    Commented Feb 15, 2018 at 22:51

1 Answer 1


Yes you can get current gas price using web3.eth.gasPrice() in Web3JS.

In geth console:


Estimate Gas:


Check below sample code for getting estimate gas consumption

      var contractID = "ADDRESS"; 
      if (typeof web3 !== 'undefined') {
          web3 = new Web3(web3.currentProvider);
      } else {
          // set the provider you want from Web3.providers
          web3 = new Web3(new Web3.providers.HttpProvider(""));

      var contractABI = web3.eth.contract(<ABI>);

      var contract = contractABI.at(contractID);
      var estGas = contract.setEmpId.estimateGas("ABC");
      var gasPrice = web3.eth.gasPrice();
      var estTransPrice = eth.gasPrice*estGas;

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.