Our React Hooks library uses react-query under the hood & will expose request parameters & response objects that mimic react-query functionality. For instance, in the request parameters you can pass the { enabled: boolean } object and other request parameters found in react-query's documentation. The response objects will also mimic react-query with { data, isLoading, isSuccess } etc.
Since we are mimicking react-query Reveel's SDK integration should feel familiar to many react devs. This also means we are essentially mimicking the request parameter & response objects used by wagmi which should also feel familiar to web3 Devs.
Functions with example uses are shown below. All the examples below use wagmi functions alongside @r3vl/sdk, but this is not a requirement. Notably, the following example is using wagmi 0.10.8
import { useCreateRevenuePath, useR3vlClient } from"@r3vl/sdk";import { ethers } from"ethers";import { useProvider, useNetwork, useSigner } from"wagmi";interfaceICreateArgs { walletList:string[][]; distribution:number[][]; tiers: { [token:'ETH'|'WETH'|'DAI'|'USDC']:BigNumberish }[] name:string; mutabilityEnabled:boolean;}exportconstCreatePathButton= ({ createArgs }: { ICreateArgs }) => {const { chain } =useNetwork();constprovider=useProvider();const { data: signer } =useSigner();useR3vlClient({ chainId:chain?.id, provider, signer, initV2Final:true,// In case you want to create a "complex" Revenue Path with tiers initSimple:true,// For revenue paths with no additional tiers configuration apiKey:'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx',// Api key is required so SDK can store and access data related to Revenue Path configuration });const { mutate: createRevenuePath } =useCreateRevenuePath();consthandleSubmit= () => {createRevenuePath(createArgs); };return (<button onClick={handleSubmit}>Create Path</button> );};
At the moment, @r3vl/sdk is compatible with the following chains:
Ethereum (mainnet & goerli)
Polygon (mainnet & mumbai)
Arbitrum (one & testnet)
Optimism (mainnet & goerli)
Aurora (mainnet & testnet)
Here a live example of a NextJS implementation of the R3VL SDK
Withdrawing From Revenue Path
import { useWithdraw } from"@r3vl/sdk";import { useAccount, useProvider, useNetwork, useSigner } from"wagmi";import { ethers } from"ethers";constrevPathAddress='0xSomeAddress'exportconstWithdrawRevenueButton= () => {const { chain } =useNetwork();constprovider=useProvider();const { data: signer } =useSigner();useR3vlClient({ chainId:chain?.id, provider, signer, initV2Final:true,// In case you want to create a "complex" Revenue Path with tiers initSimple:true,// For revenue paths with no additional tiers configuration apiKey:'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx',// Api key is required so SDK can store and access data related to Revenue Path configuration });constwithdraw=useWithdraw(revPathAddress);const { address } =useAccount();consthandleWithdraw= () => {withdraw.mutate({ walletAddress: address, isERC20:'someTokenAddress'// OPTIONAL - Address of specific erc20 token }); };return (<button onClick={handleWithdraw}>Withdraw Revenue</button> );};
Get Revenue Path Balances
a simple hook to display a user's available balances
import { useBalances } from"@r3vl/sdk";import { useAccount, useProvider, useNetwork, useSigner } from"wagmi";import { ethers } from"ethers";constrevPathAddress='0xSomeAddress'exportconstDisplayBalances= () => {const { chain } =useNetwork();constprovider=useProvider();const { data: signer } =useSigner();useR3vlClient({ chainId:chain?.id, provider, signer, initV2Final:true,// In case you want to create a "complex" Revenue Path with tiers initSimple:true,// For revenue paths with no additional tiers configuration apiKey:'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx',// Api key is required so SDK can store and access data related to Revenue Path configuration });const { address } =useAccount();const { data: balances } =useBalances( revPathAddress, { walletAddress: address,// OPTIONAL - Address of specific user wallet isERC20:'someTokenAddress'// OPTIONAL - Address of specific erc20 token }, { enabled:!!address } );return (// earnings - withdrawn = withdrawable<div display="flex"><div className="total-earnings">{balances.earnings}</div><div className="total-withdrawn">{balances.withdrawn}</div><div className="total-withdrawable">{balances.withdrawable}</div></div> );};
Get Revenue Path Tiers
a simple hook to fetch tier data from an existing revenue path
import { useBalances } from"@r3vl/sdk";import { useAccount, useProvider, useNetwork, useSigner } from"wagmi";import { ethers } from"ethers";constrevPathAddress='0xSomeAddress'exportconstDisplayBalances= () => {const { chain } =useNetwork();constprovider=useProvider();const { data: signer } =useSigner();useR3vlClient({ chainId:chain?.id, provider, signer, initV2Final:true,// In case you want to create a "complex" Revenue Path with tiers initSimple:true,// For revenue paths with no additional tiers configuration apiKey:'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx',// Api key is required so SDK can store and access data related to Revenue Path configuration });const { address } =useAccount();const { data: tiers, isFetched: tiersFetched } =useRevenuePathTiers(revPathAddress)consttier= tiers?.[0] || {}if (tiersFetched) console.log("Revenue path data:",Object.keys(tier.proportions: { [address: string]: number }).reduce((prev, curr) => {return [...prev, { address: curr, share:tier.proportions[curr] *10000000000000 } ] }, []) ))returnnull};
Updating Revenue Path
hook to update an existing revenue path in case user's wallet owns that revenue path and it's mutability is enabled
import { useUpdateRevenuePath, useR3vlClient } from"@r3vl/sdk";import { ethers } from"ethers";import { useProvider, useNetwork, useSigner } from"wagmi";interfaceIUpdateLimitsArgs { tokens:string[], newLimits:number[], tier:number}interfaceIAddRevenueTierArgs { walletList:string[][] distribution:number[][] newAddedTierLimits:number[] finalFundWalletList:string[] finalFundDistribution:number[] finalFundIndex:number}exportconstUpdateRevenuePath= ( { updateLimitsArgs, addRevenueTierArgs }: { updateLimitsArgs:IUpdateLimitsArgs addRevenueTierArgs:IAddRevenueTierArgs }) => {const { chain } =useNetwork();constprovider=useProvider();const { data: signer } =useSigner();useR3vlClient({ chainId:chain?.id, provider, signer, initV2Final:true,// In case you want to create a "complex" Revenue Path with tiers initSimple:true,// For revenue paths with no additional tiers configuration apiKey:'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx',// Api key is required so SDK can store and access data related to Revenue Path configuration });const {updateLimits,addRevenueTier } =useUpdateRevenuePath();constupdateLimitsBtn= () => {updateLimits(updateLimitsArgs); };constaddRevenueTierBtn= () => {addRevenueTier(addRevenueTierArgs); };return (<><button onClick={updateLimitsBtn}>Update Tier Limits</button><button onClick={updateLimitsBtn}>Add New Tier</button></> );};