Request form
Cookbook may introduce a token in the future. Share and contribute to be eligible for future airdrops.
close icon
relevant tag icon
Api Consumer
copy icon
Chainlink
• version 1.0.0
api
oracle

Api Consumer

The APIConsumer contract uses Chainlink, an oracle service, to request data from an external API. The contract sets the Chainlink token and oracle contract addresses in the constructor and specifies the jobId and fee variables. The requestVolumeData function creates a Chainlink request to retrieve volume data from the Cryptocompare API and sends it using the sendChainlinkRequest function. When the API response is received, the fulfill function extracts the volume data from the response and sets the volume variable. The contract also defines the withdrawLink function to allow the owner to withdraw Link tokens from the contract. More info: https://docs.chain.link/getting-started/advanced-tutorial/#contract-example

*Visit desktop site to download or deploy

Version

1.0.0

Creator

Chainlink

Recent Use

🍞 0xE9e8 downloaded

Last Publish

2/28/2023
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
requestVolumeData() :
This function is used to request volume data from an external API. It builds a Chainlink request with the job ID, address of the contract, and the selector for the fulfill function. It then adds the API URL, the path for the data, and the times amount to the request. Finally, it sends the request and returns the request ID. (autogenerated documentation)
fulfill(bytes32,uint256) :
This function is used to fulfill a request for a certain amount of data. It takes two parameters, a bytes32 _requestId and a uint256 _volume. It emits an event called RequestVolume, which contains the requestId and the volume, and then sets the volume variable to the _volume parameter. (autogenerated documentation)
withdrawLink() :
This function allows the owner of the contract to withdraw LINK tokens from the contract. It does this by calling the LinkTokenInterface contract at the address stored in the chainlinkTokenAddress() function, and then transferring the balance of LINK tokens from the contract to the msg.sender. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i Api-Consumer
copy icon

Recent Use

🍞 0xE9e8 downloaded

Last Publish

2/28/2023

Version

1.0.0

Creator

Chainlink

Cookbook is free.
Any contract you deploy is yours.
Your contract is owned and controlled by you.