docs
Complete Real Example
2. Deploy your consumer

Deploy your Consumer

In this section, we will guide you through the process of deploying your consumer contract to interact with the OracleRouter. Let's get started!.
We are going to start by cloning a public repository with the essentials configured to deploy an example consumer.

git clone https://github.com/ddrr1337/eyeOracle_public.git

Now you have a minimal Hardhat project to deploy an example contract.

Enter the repository folder and:

yarn install

Now create an .env file at root project folder and use example.env as reference to fill necesary data

SEPOLIA_RPC=<your sepolia https provider>
PRIVATE_KEY=<your wallet private key>
ETHERSCAN_TOKEN=<sepolia etherscan token to verify your contract>

Open ExampleContract.sol to edit exampleSendRequestPOST() function.

Set up your own host and port as we did in the previous section server.js file.

ExampleContract.sol
    function exampleSendRequestPOST(
        uint256 fulfillGasUsed,
        string memory valueInput_1,
        string memory valueInput_2
    ) external payable nonReentrant {
        uint256 gasCost = gasCostFulfill(fulfillGasUsed);
 
        require(
            msg.value > gasCost,
            "ETH sent is less than gas cost for the callback"
        );
 
        string memory url = "http://<your host>:<port>/api/data/";
 
        string memory requestBody = string(
            abi.encodePacked(
                '{"arg_1":"',
                valueInput_1,
                '","arg_2":"',
                valueInput_2,
                '"}'
            )
        );
 
        OracleRequest.Request memory req;
 
        req.url = url; //requiered
        req.method = "POST"; //required
        req.slot = "0"; // <-- SELECT SLOT YOU WANT TO USE FOR THIS REQUEST
        req.jsonResponsePath = "data.result";
        req.requestBody = requestBody;
        testerCustomBody = req.requestBody;
        req.bodyValuesDataTypes = '["uint256","uint256"]'; // remember double quote in elements of string array for match json format
        //req.allowFloatResponse = true; <-- uncomment this line if you are specting a float to return (IF YOU DO, BOTH UINT AND FLOAT WIL BE MUL BY 10**18 BEFORE SENDING THE ORACLE RESPONSE)
 
        bytes memory requestData = req.encodeCBOR();
 
        //this will emit a event on OracleRouter that nodes will caputure
        //msg.value is sent here
        uint256 requestId = _sendRequest(requestData, fulfillGasUsed);
 
 
    }

Now you can deploy your contract.

yarn hardhat deploy --tags example --network sepolia

Note: This deployment script also includes a script to add the consumer to the oracle, so in the next step, you won't need to add it again.