The parameters string "p" in the Chainlink request contains all the necessary information to make a call to the external adapter. It is structured as a JSON object string.
In order to make calls to Adapter.js more gas efficient, all variables contained in the parameters string use only a single character, which shortens the parameters string.
The following documentation describes what each variable in the request means and how it is structured. This information can be used to modify a request to Adapter.js on-chain by
modifying the parameters string before it is added to the Chainlink request.
Below is an example of the parameters JSON object string being added to a Chainlink request.
chainlinkRequest.add('p',
"{\"t\":\"uint256\",
\"m\":\"post\",
\"u\":\"https://jsonplaceholder.typicode.com/posts\",
\"d\":{\"username\":\"MYUSERNAME\",\"id_num\":123},
\"h\":{\"Authorization\":\"Bearer ABCD1234\"},
\"j\":\"return response.data.id_num;\"
}");
Variables in the Parameters JSON Object String
t: Return Type
-
Specifies the Solidity type that will be returned on-chain. The options are int256, uint256, bool or bytes32.
-
This value must be included.
m: HTTP Request Method
-
Specifies the HTTP method to use in the HTTP request which can be either get, post, put, delete, patch, head, options, or trace.
-
Do not include this value to make a request without performing an HTTP request.
u: URL
-
Specifies the URL for the HTTP request.
-
This value must be included if the HTTP request method, m, is specified.
h: HTTP Request Headers
-
Directly specifies the headers JSON object to be used in the HTTP request.
-
Since this value is included directly in a request, this value is publicly visible on the blockchain.
-
To use headers in the HTTP request, either this value or headers reference ID, r, should be included, but not both.
r: HTTP Headers Reference ID
-
Specifies the reference ID for headers object that has been uploaded to the external adapter.
-
The reference ID must match the reference ID that was entered when the headers were uploaded.
-
If a contract has multiple different sets of uploaded headers, the reference ID for each set of headers must be unique.
-
Only requests made by a contract address that was entered when the headers were uploaded can use
the referenced headers in the HTTP request.
-
To use headers in the HTTP request, either this value or the directly provided headers value, h, should be included, but not both.
d: HTTP Request Data
-
Specifies the JSON object to be used in the body of the HTTP request.
-
This value can be included for the HTTP methods, post, put, delete and patch, which have request bodies.
-
This value is optional if no data should be used in the body of the HTTP request.
j: JavaScript
-
A string which contains the JavaScript to be executed, where the returned value is returned by the Chainlink request.
-
The provided code is wrapped in a function before it is executed by the external adapter.
-
Code can only contain vanilla Node.js code, without any imports.
-
The maximum execution time for both the HTTP request and the provided JavaScript must be under 30 seconds.
-
The maximum memory usage for an entire Adapter.js instance is 256 megabytes.
-
The result of the HTTP request can be accessed by using the variable
response
in the provided JavaScript code.
To access the data returned by the HTTP request, use response.data
.
-
Either this value should be included should be included or the IPFS content ID, but not both.
i: IPFS Content ID
-
Specifies the IPFS content ID of the file which contains the JavaScript which should be executed in the request.
-
The code in the uploaded file is executed the same way and has the same constraints as if the code were sent as a string, as described above.
-
The file uploaded to IPFS must be a single JavaScript file.
-
JavaScript files can easily be uploaded to IPFS using Web3.Storage via the Adapter.js simulator.
-
Either the IPFS content ID or JavaScript value, j, should be included, but not both.
If you are having difficulty making an on-chain request with Adapter.js, please follow the troubleshooting steps below.
-
Confirm that the contract is funded with LINK.
-
Verify that the request is valid by using the simulator. The simulator sends requests directly to the external adapter so if it works in the simulator it should work on-chain,
provided the request is structured the same way.
-
Use the code generator to check how the request parameters string should be structured.
-
Verify the correct oracle address and LINK token contract address are used for the particular blockchain to which the contract is deployed.
-
Check that the job ID is correct for the oracle to which the request is being sent.
-
Ensure any required headers have been successfully uploaded to the external adapter and that the correct reference ID is being used.
If you have read the documentation and followed the troubleshooting steps but are still encountering difficulties, please reach out via Discord.