4

I need to call two functions in an already deployed contract I do not own in an atomic transaction. I thought the simplest way to do this would be to wrap the two functions in a new contract function.

contract deployedContract {
  function A(uint a1, ...) {}
  function B(uint b1, ...) {}
}

contract myContract {
  function C(uint a1, a2, b1, b2, ...) {
   // pseudo code
   deployedContract.A(a1, a2, ...);
   deployedContract.B(b1, b2, ...);
  }
}

However, the total number of parameters in the two methods I need to call is 20, and therefore I get the stack too deep exception from the Solidity compiler.

Is there any way to make two function calls from a web3 node client atomic?

Thanks

2

If you can cast all your parameters to uint you can pass all of them in an array. I think you can pass above 50 uint in an array, but it depends on the block limit.

contract myContract {
  function run(uint[] p) {
   deployedContract.A(address(p[0]), bytes32(p[2]), ...);
   deployedContract.B(uint(p[1]), uint128(p[3]), ...);
  }
}

Another option is to first send half of the parameters and store in the contract. And then in a second call pass the remaining params, and execute both functions.

contract myContract {
  uint a1;
  uint b1;
  function prepare(uint _a1, uint _b1...) {
    a1 = _a1;
    b1 = _b1;
    ...
  }
  function execute(uint _a2, uint _b2, ...) {
   // pseudo code
   deployedContract.A(a1, _a2, ...);
   deployedContract.B(b1, b2, ...);
  }
}
1
  • Thanks Ismael, both answers work well. I chose the array option as it required only 1 transaction instead of 3. – Dan H Oct 5 '17 at 9:16

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.