Actions

External Initiators: Difference between revisions

From Chainlink Community Wiki

No edit summary
No edit summary
Line 8: Line 8:
The example is writing three pieces of information on-chain; two strings and an uint.
The example is writing three pieces of information on-chain; two strings and an uint.


'''String 01:'''  <code>FeedName</code>
'''String01:'''  <code>FeedName</code>
 
'''String02:'''  <code>FeedID</code>
 
'''Decimal01:'''  <code>1234567.89</code>
 
----
==Create Job==
We will need to create a job for the external initiator to run.
 
Due to the fact that the inbound web request to the node will need to include the unique Job ID for the desired job, we will have to deploy the job before we can create the external initiator.
 
'''Note:''' The name value in the json portion of the below job spec example must match the name of the external initiator you create in the next step
 
Example job spec:
 
<pre style="white-space:pre-wrap; width:100%; border:1px solid lightgrey; background:black; color:white;">type            = "webhook"
name            = "External Initiator Example 01"
schemaVersion  = 1
externalInitiators = [
  { name = "$EXTERNAL_INITIATOR_NAME", spec = "{}" }
]
observationSource  = """
    data        [type="jsonparse" data="$(jobRun.requestBody)"]
 
    encode_tx    [type="ethabiencode"
          abi="myFunc(string string1, string string2, uint256 num1)"
          data="{ \\"String01\\": $(data.string1), \\"String02\\": $(data.string2), \\"Decimal01\\": $(data.num1) }"]
 
    submit_tx    [type="ethtx"
          to="$CONTRACT_ADDRESS"
          data="$(encode_tx)"
          failOnRevert="true"]
 
    data -> encode_tx -> submit_tx
"""
</pre>


'''String 02:'''  <code>FeedID</code>


'''Uint:'''  <code>1234567.89</code>


----
----
Line 33: Line 67:


*Whatever name you give it, will appear as the name in the database, so I recommend you name it something specific to the job.
*Whatever name you give it, will appear as the name in the database, so I recommend you name it something specific to the job.
----
==

Revision as of 20:57, 9 January 2023

External Initiators

Official Chainlink Docs for External Initiators


Example Details for the Document

To help get a better understanding of how external initiators work, we will run through an example in the doc.

The example is writing three pieces of information on-chain; two strings and an uint.

String01: FeedName

String02: FeedID

Decimal01: 1234567.89


Create Job

We will need to create a job for the external initiator to run.

Due to the fact that the inbound web request to the node will need to include the unique Job ID for the desired job, we will have to deploy the job before we can create the external initiator.

Note: The name value in the json portion of the below job spec example must match the name of the external initiator you create in the next step

Example job spec:

type            = "webhook"
name            = "External Initiator Example 01"
schemaVersion   = 1
externalInitiators = [
  { name = "$EXTERNAL_INITIATOR_NAME", spec = "{}" }
]
observationSource   = """
    data         [type="jsonparse" data="$(jobRun.requestBody)"]

    encode_tx    [type="ethabiencode"
          abi="myFunc(string string1, string string2, uint256 num1)"
          data="{ \\"String01\\": $(data.string1), \\"String02\\": $(data.string2), \\"Decimal01\\": $(data.num1) }"]

    submit_tx    [type="ethtx"
          to="$CONTRACT_ADDRESS"
          data="$(encode_tx)"
          failOnRevert="true"]

    data -> encode_tx -> submit_tx
"""



Create External Initiator

In order to create an external initiator, we need to get access to the Chainlink command line (CLI)

We'll accomplish this by entering into our Chainlink docker container

docker exec -it $CHAINLINK_CONTAINER_NAME /bin.bash

You will be prompted to log in.

Your login credentials are the same email address and password combination you use to login to the web UI

Once authenticated, we can create our external initiator.

chainlink initiators create $EXTERNAL_INITIATOR_NAME $EXTERNAL_INITIATOR_URL

In the above example command, the $EXTERNAL_INITIATOR_NAME would be whatever you want it to be.

  • Whatever name you give it, will appear as the name in the database, so I recommend you name it something specific to the job.

==