[Ethereum] calling a contract function from another contract [out of gas]

contract-invocationgasout-of-gastransactions

Consider the following two contracts A and B. Suppose I store these in
a and b. Then when I make a call and try to pass two addresses as follows:

a.reqswap(b.address,eth.accounts[0],eth.accounts[1])

it does NOT increment the counter. I make sure there is ether in the contracts
a and b.

On the other hand, if I delete the address arguments x,y and all statements
that contain x,y from the code and just call :

a.reqswap(b.address)

This time it works and the b.counter is incremented.

As I said, I do make sure eth.defaultAccount is set and that also
there are ethers in the contracts (so as to provide gas).


contract A {

    address  public owner;
    uint     public counter ; 
    B b ;
    address public bc ;
    address public bo ; 

    modifier owneronly {
        if (msg.sender != owner)
            throw;
        _
    }

    function A() {
        owner = msg.sender;
        counter = 1 ; 
    }

    function increment(address x,address y) public {
       counter = counter + 1 ;
       bc = x ;
       bo = y ; 
    }

    function reqswap(address baddr,address x,address y)  public {
        b = B(baddr)  ; 
        b.increment(x,y) ; 
    }
}


contract B {

    address  public owner;
    uint     public counter ; 
    A a ;
    address public ac ; 
    address public ao ;

    modifier owneronly {
        if (msg.sender != owner)
            throw;
        _
    }

    function B() {
        owner = msg.sender;
        counter = 1 ; 
    }

    function increment(address x,address y) public {
       counter = counter + 1;
       ac = x ;
       ao = y ; 
    }

    function reqswap(address aaddr,address x,address y)  public {
        a = A(aaddr)  ; 
        a.increment(x,y) ; 
    }
}

Best Answer

Having enough Ether is still different from how much gas is specified in the transaction. This question was resolved by increasing the gas: a.reqswap(b.address, eth.accounts[0], eth.accounts[1], {gas:120000})


General tip: When things have been debugged, some scenarios work, and some don't, try increasing the gas in the transaction.

Related Topic