Skip to content

React + Redux library to fetch starknet state at each new block through batched and cached calls.

Notifications You must be signed in to change notification settings

ruleslabs/serum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SERUM (Starknet Redux Multicall)

React + Redux library to fetch starknet state at each new block through batched and cached calls.

Setup

yarn add @rulesorg/serum or npm install @rulesorg/serum

Usage

import { combineReducers, createStore } from 'redux'
import { createMulticall } from '@rulesorg/serum'

// Create a multicall instance
export const multicall = createMulticall({ reducerPath: 'multicall' })

// Create multicall redux store
const reducer = combineReducers({ [multicall.reducerPath]: multicall.reducer })
export const store = createStore(reducer)

// Multicall hooks must be called inside the Multicall Updater
export function MulticallUpdater() {
  const latestBlockNumber = useLatestBlockNumber()
  const contract = useMulticallContract()

  return <multicall.Updater latestBlockNumber={latestBlockNumber} contract={contract} />
}

Hooks

useMultipleContractSingleData

const ETH_TOKEN_ADDRESS = '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7'
const DAI_TOKEN_ADDRESS = '0x03e85bfbb8e2a42b7bead9e88e9a1b19dbccf661471061807292120462396ec9'

const results = multicall.hooks.useMultipleContractSingleData(
  latestBlockNumber,
  [ETH_TOKEN_ADDRESS, DAI_TOKEN_ADDRESS],
  ERC20ABI as Abi,
  'balanceOf',
  { address }
)

console.log(results[0]?.result?.balance) // ETH balance as Uint256
console.log(results[1]?.result?.balance) // DAI balance as Uint256

Disclaimer ⚠️

This repo contains highly experimental code. Use at your own risk.

Credits

This library is inspired by @uniswap/redux-multicall.

About

React + Redux library to fetch starknet state at each new block through batched and cached calls.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published