Currently I have a hosted wallet Solidity contract as described below. It has a execute() method that calls another contract from a hosted wallet. However looks like call() uses the balance of the original caller (owner) as the gas fee. I'd like to account this fee to the hosted wallet balance. What options I have and are the following viable

  • call() or similar method that uses the balance of the current contract as the gas fee instead of the balance of the caller

  • The original execute() caller calculates the cumulative gas cost and the end of transaction (from transaction receipt RPC API) and calls another method in the hosted wallet to credit this back to the original caller in a separate transaction

Contract code:

     * Simple hosted wallet contract.
    contract Wallet {

        // Smart contract call events
        event PreExecute(address to, uint value, uint gas);
        event Execute(address to, uint value, uint balanceAfter, uint spentGas);
        event ExceededExecuteWithValue(address to, uint value);
        event FailedExecute(address to, uint value, uint balanceAfter);

        // Who is the owner of this hosted wallet. This is the (coinbase) address or geth node
        // that your server speaks to via RPC
        address owner;

        function Wallet() {
            // Lock down the wallet, so that only our private geth
            // has the owner private key to speak to us
            owner = msg.sender;

         * Executes a transaction from this wallet.
         * We call a function in another smart contract and for the gas use value stored on this contract.
        function execute(address _to, uint _value, uint _gas, bytes _data) external {

            uint balanceBefore;
            uint balanceAfter;
            bool success;

            if(msg.sender != owner) {

            if(_value > this.balance) {
                ExceededExecuteWithValue(_to, _value);

            balanceBefore = this.balance;

            // http://ethereum.stackexchange.com/a/2971/620
            if(_value > 0) {
                success = _to.call.value(_value)(_data);
            } else {
                success = _to.call(_data);

            balanceAfter = this.balance;

            if(success) {
                Execute(_to, _value, balanceAfter, (balanceBefore - balanceAfter) - _value);
            } else {
                FailedExecute(_to, _value, balanceAfter);

         * Somebody sends ETH to this contract address
        function() {
            // just being sent some cash?
            if (msg.value > 0) {
                Deposit(msg.sender, msg.value);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.