Using Templates (RRP)
A request to an Airnode can have many parameters. It is very common for requester contracts (e.g., a data feed) to make repeated requests with the exact same parameters. In such instances, it is wasteful to pass all of these parameters repeatedly. Templates are used to hold a set of parameter values on-chain that can be used repeatedly when calling themakeTemplateRequest()
function in AirnodeRrpV0.sol. UnlikemakeFullRequest(), makeTemplateRequest()
requires that a requester passtemplateId
which identifies a template.
function makeTemplateRequest(
bytes32 templateId,
address sponsor,
address sponsorWallet,
address fulfillAddress,
bytes4 fulfillFunctionId,
bytes calldata parameters
) external override returns (bytes32 requestId) {
2
3
4
5
6
7
8
When a template is used to make a request, both the parameters encoded in parameters of the template and parameters provided at request-time (if any) will be used by the Airnode. In case the two include a parameter with the same name, the one provided at request-time will be used.
The structure of a template, as shown below, is simple.
- address of the desired Airnode
- endpointId from the Airnode
- endpoint parameters
struct Template {
address airnode;
bytes32 endpointId;
bytes parameters;
}
2
3
4
5
See the guide Making RRP Template Requests and learn how to create and use a template. Also visit the coingecko-template monorepo example demonstrates template requests.
FLEX_END_TAG