I'm new to smart contracts, so please be gentle ;)

I'm having trouble deploying a contract to testrpc using truffle.

$ truffle deploy

Error deploying LFC:

Error: VM Exception while executing transaction: out of gas

Here's my contract:

import "Mortal.sol";
import "Exchanger.sol";
import "ExternalStorage.sol";
import "DepositDB.sol";
import "ForexDB.sol";
import "OrderDB.sol";
import "ContractManagerDB.sol";

contract LFC is Mortal {

    // ForEx exchanger
    // Steve Huckle

    bytes3 private constant defaultBaseCurrency = "Eth";

    bytes32 private constant orderName = "Order DB";
    bytes32 private constant forexName = "Forex DB";
    bytes32 private constant depositName = "Deposit DB";    

    Exchanger private exchanger;
    ExternalStorage private storageContract;
    OrderDB private orderDB;
    DepositDB private depositDB;
    ForexDB private forexDB;
    ContractManagerDB private contractManagerDB;

    //event ExchangerCreated(address ex, uint now);

    function createExchanger() public {
        exchanger = new Exchanger();

    function createStorage() public onlyOwner {
        storageContract = new ExternalStorage();

    function createContractManager() public onlyOwner {
        contractManagerDB = new ContractManagerDB();

    function createOrderContract() public onlyOwner {
        orderDB = new OrderDB();

    function createForexContract() public onlyOwner {
        forexDB = new ForexDB();

    function createDepositContract() public onlyOwner {
        depositDB = new DepositDB();

    function addAdmin() public onlyOwner {

    function addContracts() public {

    function setForexBase() public {

    function getExchanger() public constant returns (address) {
        return exchanger;

Any help and/or explanation as to how to overcome the issue and what I'm doing wrong would be very gratefully received. The problem appears to be with doing too many "new's". Is that approach unusual? Rather than doing it that way, instead, should I deploy the dependent contracts and then pass their addresses into the contract above?

  • 1
    It looks like your contract is very big and needs a lot of gas. In truffle console, can you try LFC.new({from: account, gas: 3000000}). If this fails, try bigger values. If this fails, you need to parcel out into different components. You should also move to using Truffle v2. Sep 15 '16 at 13:27
  • Upgraded to Truffle v2, which is cool - but it now uses a whole new method of deployment, which is probably cool further down the road, but not so cool when I just want to quickly run "truffle deploy" the old way ;)
    – glowkeeper
    Sep 15 '16 at 15:56

You can only use up to ~4.5 million gas per block. If your contract is very large, it may require more than that. The solution is to deploy each individual contract separately, then pass their addresses to the constructor of the main contract, so that the gas cost is spread across multiple transactions.

  • Yeah - reading the docs a bit further, I was fast coming to the conclusion that the way to go is deploying all the dependent contracts and then passing in their addresses to the constructor of LFC. But, who owns the dependent contracts doing it that way? Will it be the account of the person who passes in the addresses to LFC?
    – glowkeeper
    Sep 15 '16 at 15:55
  • No one "owns" contracts.... They do what's in the code, it doesn't matter who created them. If you specifically set an owner in the constructor, you should just allow the owner to give ownership to another address. If you're using the Mortal and onlyOwner contracts, you should really read their source code and understand what they're doing. It's not very coplicated Sep 15 '16 at 21:42
  • Ah yes - owner = msg.sender. Forgive me for asking a silly question and suffering from a moment of stupidity :(
    – glowkeeper
    Sep 16 '16 at 10:11

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.