Step 4. Build your automation workflow
Last updated
Last updated
First, we need to configure our trigger.
To start, click on “Block” in our workflow.
This will open a separate tab for configuring the trigger. Within this tab, we specify the chain by choosing Polygon Mumbai and ask the Nerif Network to trigger an automation workflow after each 5th block (~ every 10 seconds) is added to the Polygon Mumbai network.
Once ready, click “Confirm”.
Now, let’s proceed with building our automation workflow. To add a new workflow element we click on “Add step” and press “Action”.
At this point, we want to know if the price of the ETH/USDT pair has changed via API and send this value to our smart contract. To do that, first, select “Webhook” (will be sending HTTP requests) and press “Confirm”.
Now, let’s configure our Webhook by clicking on “Webhook” in our workflow.
This will open a separate tab for configuring the Webhook. Within this tab, we:
specify the HTTP request method by choosing GET within a drop-down list
enter the URL address of the webhook
specify the authorization header by including the API key directly in the authorization header of the API request (blurred in the example below).
This will allow our workflow to check the price of the ETH/USDT pair at coinapi.io.
An example of the response that we’ll be getting from coinapi.io looks like this:
{
"time": "2023-06-14T11:33:39.0000000Z",
"asset_id_base": "ETH",
"asset_id_quote": "USDT",
"rate": 1749.4840032743821694344049744
}
Once ready, click “Confirm”.
As we’ll be getting the price of ETH via Webhook, we now want to transfer such a price to our smart contract.
We’ll be doing that via eth_call.
First, let’s click on “Add step” and select “Action” in our workflow.
Select eth_call (an Ethereum API method that executes a smart contract function call without creating a transaction on the blockchain, it does not change a state) and press “Confirm”.
Now, let’s configure eth_call by clicking on it within our workflow which will open a new tab.
We need to specify the chain and select the contract we added previously in Step 2 in a drop-down list. As we want our workflow to check if the price of the ETH/USDT pair changed, we will select the function priceChanged. This function returns a boolean variable if the currently stored price within the smart contract is different from the one we got from coinapi.io.
The final step here is to pass the received price of the ETH/USDT pair via coinapi.io to the function priceChanged. We will do that by referring to the Webhook output field.
After that, click “Confirm”.
At this point, our workflow looks like this:
Next, we want to determine what happens once Nerif Network checks if the price for ETH/USDT pair has changed. To do that, click on “Add step” and select “Condition”.
Enter the details for Condition, as in the example below, and press “Confirm”.
After that, we have two options for what happens once Nerif Network checks if the price for ETH/USDT pair has changed, i.e. “False” and “True”.
For False, click “Add step” and select “Exit”. This means that if the price for ETH/USDT pair didn’t change, the automation workflow does not proceed further.
For True, click “Add step” and select “Action”.
Assuming the price for ETH/USDT pair has changed, we want the automation workflow to proceed further to pass the updated price to the PriceFeed contract. To do that, we choose “Transaction” as our action type.
Now, let’s add the needed details for the transaction, as per the example below.
First, click on the “Transaction” within our workflow which will open a new tab.
In this tab, we specify the Polygon Mumbai chain, select the PriceFeed contract address in a drop-down list, and set the gas limit. Most importantly, we choose the function updatePrice. This means that the automation workflow will proceed to update the price if the price of the ETH/USDT pair has changed.
Now, to update the price within the PriceFeed smart contract with the price of ETH/USDT pair received via the Webhook, we should make a reference to the Webhook output field.
After we put in all the transaction details, click “Confirm”.
Finally, click “Publish” in the top right corner and confirm the transaction in your wallet to publish your workflow within Nerif Network. After that, your automation workflow is all set, congrats!