Quick Start - Integrate with Skyfire-Enabled API
Integration with a Skyfire-enabled API involves creating a claim from Skyfire, then sending that claim in the request header to access payment-gated API.
-
Step 1: Install the Skyfire SDK
npm install @skyfire/sender-sdk
-
Step 2: Initialize the SDK
import { SkyfireClient } from '@skyfire/sender-sdk' const skyfire = new SkyfireClient({ apiKey: 'YOUR_API_KEY' })
-
Step 3: Create a claim
// create claim using the quote try { const claim = skyfire.createClaim({ api: 'api-ninja', request: { url: 'v1/stockprice', payload: { ticket: 'APPL' } } }) } catch (err) { // Error can be thrown if the claim cannot be created. // For example, if the error is due to insufficient funds, you can top up your account if (err instanceof Skyfire.InsufficientFundsError) { // note: use your own wallet to send funds to the Skyfire wallet const amountToSend = ethers.utils.parseUnits('100', 6) // 100 USDC // SKYFIRE_WALLET_ADDRESS can be found on the dashboard usdcContract.transfer(SKYFIRE_WALLET_ADDRESS, amountToSend) } else { throw err } }
-
Step 4: Make a request request to the Skyfire-Enabled API using the claim token
// make a request to a Skyfire-enabled API const rsp = await axios.get( 'https://api.api-ninjas.com/v1/stockprice?ticker=APPLE', { headers: { 'x-skyfire-claim': claim.token } } ) console.log(rsp.data)
Updated 4 months ago