Skip to content

cqlyj/simple-chainlink-function

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Chainlink Function

This just a simple chainlink function that returns balance of an address by calling the blockscout API.

Getting Started

Requirements

  • git
    • You'll know you did it right if you can run git --version and you see a response like git version x.x.x
  • foundry
    • You'll know you did it right if you can run forge --version and you see a response like forge 0.2.0 (816e00b 2023-03-16T00:05:26.396218Z)

Quickstart

git clone https://github.com/cqlyj/simple-chainlink-function.git
cd simple-chainlink-function
make

Usage

  1. Set up your environment variables:
cp .env.example .env
  1. Fill in the .env file with your own values. And also replace the address anywhere you see in files with your own address.
  2. Deploy the SimpleBalance contract:
make deploy-simpleBalance
  1. Grab the address of your deployed contract and go to the chainlink function subscription page. Create your subscription, add funds, and add the contract address as consumer address.

  2. As you get the subscription ID, go to the ./script/Interactions.s.sol file and update with yopur subscription ID.

contract SendRequest is Script {
    SimpleBalance simpleBalance;
-   uint64 subscriptionId = 3995;
+   uint64 subscriptionId = YOUR_SUBSCRIPTION_ID;
    string[] args = new string[](0);

    function sendRequestToGetBalance(address mostRecentlyDeployed) public {
        simpleBalance = SimpleBalance(mostRecentlyDeployed);
-       vm.startBroadcast(0xFB6a372F2F51a002b390D18693075157A459641F);
+       vm.startBroadcast(YOUR_ADDRESS); // Don't forget to replace with your address
        simpleBalance.sendRequest(subscriptionId, args);
        vm.stopBroadcast();
    }
    .
    .
    .
  1. Run the script:
make send-request
  1. Check in the chainlink function page for the pending request and once it's done, you can check the balance of the address by running:
make get-balance

That's it! You should see the balance of the address!

Contact

Luo Yingjie - luoyingjie0721@gmail.com

About

simple chainlink function calling blockscout apis demo

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published