Typescript SDK
Installation
To add the Renegade SDK to your project, install the required packages.
npm install @renegade-fi/node@latest @wagmi/core viem@2.x
This SDK is responsible for interacting with a relayer. Some actions, such as createWallet
or deposit
, require using your Ethereum wallet to sign messages or approve tokens. To perform these actions, we recommend using wagmi and viem.
Create Config
Create and export a new Renegade config using createConfig
.
import { createConfig } from "@renegade-fi/node"
import { createPublicClient, http } from 'viem'
import { arbitrum } from 'viem/chains'
const viemClient = createPublicClient({
chain: arbitrum,
transport: http()
})
export const config = createConfig({
chainId: arbitrum.id,
darkPoolAddress: "0x30bd8eab29181f790d7e495786d4b96d7afdc518",
priceReporterUrl: "mainnet.price-reporter.renegade.fi",
relayerUrl: "mainnet.cluster0.renegade.fi",
viemClient,
})
If you have your chain ID configured in your .env
file, you can use the isSupportedChainId
function to check if a chain is supported. This function also acts as a type guard, narrowing the type to SupportedChainId
when it returns true
.
import { isSupportedChainId } from "@renegade-fi/node"
// Get chain ID from environment variables and convert to number
const chainId = Number(process.env.CHAIN_ID)
const isSupported = isSupportedChainId(chainId)
if (isSupported) {
// chainId is now narrowed to SupportedChainId type
console.log("Chain is supported: ", chainId)
} else {
console.log("Chain is not supported")
}
Follow the instructions here to properly configure viemClient
for either the Arbitrum One chain or the Arbitrum Sepolia chain, depending on which environment you want to use.
darkPoolAddress
is the address of the darkpool proxy contract, not the implementation contract itself. You can find the darkpool proxy address for your environment here.
Use the SDK
Now, you can pass the config
to use actions.
import { backOfQueueWallet } from "@renegade-fi/node"
const wallet = await getBackOfQueueWallet(config)
console.log("Wallet balances: ", wallet.balances)
Environment Setup
We recommend using Node v22 as it provides a WebSocket client to Node.js without external dependencies. If you are on a lower version of Node, you should provide your own WebSocket client, such as ws
.
This SDK makes exclusive use of ES Modules. Check out this guide for more info on ESM support and Frequently Asked Questions across various tools and setups.
For Typescript configuration, check out this example repo for a reference tsconfig.json
.
Protocol Core Concepts
Relayer
A relayer node is resposible for the matching and settlement of orders. Each individual relayer manages one or more wallets, meaning they are able to view the plaintext wallet but are unable to modify a wallet. In order to modify a wallet (placing orders, depositing assets, etc.), users sign updates to their wallet state and queue asynchronous "tasks" in the relayer.
Relayers manage task queues for each wallet, which means you do not necessarily need to wait for a task to complete before creating a new task. This is why two functions exist for fetching a wallet's state: getWalletFromRelayer
(current wallet state) and getBackOfQueueWallet
(wallet state after current task queue is cleared).
Wallet
A wallet is a data structure that contains a user's balances, orders, and keys. To create a wallet, you must sign a message using your Ethereum wallet to generate a derivation key. This derivation key is used to derive the required fields of a wallet, such as the keychain. Learn more about keychains here.
SDK Core Concepts
Config
The Config
object is responsible for storing Renegade wallet state and internals. Most actions require a Config
object to be passed as the first argument, as it contains the derivation key used to derive keys used to sign API requests and wallet updates.
Auth Config
The AuthConfig
object is specifically used to interact with the relayer using API keys. If you are using a managed Renegade wallet, you will not need to interact with this object. If you are a permissioned user with API keys, you should follow the instructions here to create an AuthConfig
object.
External Config
The ExternalConfig
object is used to interact with the relayer using an Externally Managed Wallet. The main difference between this and the Config
object is that the ExternalConfig
object does not contain a derivation key. Instead, the user will derive required fields of a wallet, such as the keychain, and custody the wallet secrets themselves. Learn more about Externally Managed Wallets here.