0

(UPDATED)

The contract should have more than enough ETH. I deploy the contract with 0.1 ETH: https://git.io/JUBdy

const consumerExample = await ConsumerExampleFactory.deploy(process.env.REGISTRATION_GATEWAY_ADDRESS, { value: ethers.utils.parseEther("0.1") });

The contract then sends a transaction with a value of 100 wei to another contract: https://git.io/JUBd9

constructor(address simplorRegistrationGatewayAddress) SimplorConsumer(simplorRegistrationGatewayAddress) payable {
    registerSimplorEvent("RequestEthPriceEvent");
}

and

function registerSimplorEvent(string memory eventName) public payable {
  _registrationGateway.registerEvent{ value: 100 }(
    eventName,
    address(this)
  );
}

Then an event is triggered (https://git.io/JUBd7) to which a node responds (https://git.io/JUBd5) to fulfillInt (https://git.io/JUBdF) which then (in the SimplorFulfill modifier) is supposed to send 100 wei back to the node's address (https://git.io/JUBdN).

Calling the method that triggers the event:

const ethPrice = await consumerExample.requestEthPrice()

A node listening for it and sending back data:

consumers[callbackContractAddress].methods[fulfillTypeMethod](fulfillCallback, response.value, requestId, response.requestPrice).send({
  from: process.env.NODE_ACCOUNT
}).then(tx => { ...

(fulfillTypeMethod = "fulfilInt", response.requestPrice = 100)

The receiving function:

function fulfillInt(
  bytes4 fulfillCallback,
  uint256 value,
  uint256 requestId,
  uint256 requestPrice
) external onlySimplOracle SimplorFulfill(requestId, requestPrice) {...

and finally in it's second modfier:

modifier SimplorFulfill(uint256 requestId, uint256 requestPrice) {
  // check/increase confirmations
  require(_simplorCurrentResponses[requestId] < _simplorRequiredResponses[requestId], "Request already confirmed.");
  require(address(this).balance > requestPrice, "Consumer does not have enough ETH to pay for the fulfillment.");
  _simplorCurrentResponses[requestId]++;
  // transfer 100 wei (TODO: calculate/set fees)
  payable(tx.origin).transfer(requestPrice); // This seems to cause the "out ouf gas" error.

  _;
}

UPDATE I added the second require(...) to check if the consumer has anough ETH.

Causes: Returned error: VM Exception while processing transaction: out of gas

Remember the contract was deployed with 0.1 ETH and already managed to send 100 Wei to the _registrationGateway when calling registerSimplorEvent in its constructor.

The requestPrice comes from another package (https://git.io/JUBb9):

return {
  value: result.data.ethereum.usd * 100,
  type: 'int', // currently supported: 'bool', 'int' and 'string'
  requestPrice: 100 // Wei
}

Here is my repository with the full code: https://github.com/mktcode/simplor/blob/master/contracts/SimplorConsumer.sol#L81

  • 1
    Your problem is not in the aforementioned line of code. – goodvibration Sep 16 at 5:42
  • @goodvibration Hm.... but I reduced the code to basically what you see above and it really seems to depend on this line. But you are saying it is not in the provided code because that simply must work? I'll investigate further now... Also feel free to take a look at the repository. The full code is there. – Markus Kottländer Sep 16 at 12:22
  • I did, and I was not convinced that you had correctly "tracked the issue down to this push". – goodvibration Sep 16 at 12:46
  • In addition to that, things like if (_simplorCurrentResponses[requestId] == _simplorRequiredResponses[requestId]) made me wonder if you had any idea of what you're doing. – goodvibration Sep 16 at 12:46
  • Ehmm... I'm learning. Sorry for that. Maybe you can explain why this is bad? – Markus Kottländer Sep 16 at 12:54
0

Edit: Sorry, the below information is only for in-memory arrays as said by @goodvibration.

You're not allocating memory for your array, i.e., you don't instantiate it with the new operator, see https://solidity.readthedocs.io/en/v0.7.1/types.html#allocating-memory-arrays.

So when trying to push on an array that wasn't instantiated yet, it will fail.

_simplorIntResponses[requestId] = new uint256[]()
| improve this answer | |
  • 1
    That's wrong. This array is in storage, not in memory. – goodvibration Sep 16 at 5:41
  • @goodvibration True. – Markus - soliditydeveloper.com Sep 16 at 5:59
  • And as I mentioned in a comment to the question, the problem is elsewhere (not in the provided code). – goodvibration Sep 16 at 6:01

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.