(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
if (_simplorCurrentResponses[requestId] == _simplorRequiredResponses[requestId])
made me wonder if you had any idea of what you're doing. – goodvibration Sep 16 '20 at 12:46