Skip to main content

Use Delegate.xyz JavaScript SDK

Overview

This guide explains how to use the Delegate.xyz JavaScript SDK to fetch a list of incoming delegations for a connected wallet, and set a wallet as a delegate for the specified account.

Prerequisites

Installation

npm install @delegatexyz/sdk viem

For writing transactions, we recommend using the Ronin Wallet SDK.

npm install @roninnetwork/wallet-sdk 

Examples

Incoming delegations

This example checks if a specific to address is set as a delegate for all tokens of a from address.

import { http } from "viem";
import { DelegateV2 } from "@delegatexyz/sdk";

(async() => {
const RPC_URL = "https://api.roninchain.com/rpc";
const v2 = new DelegateV2(http(RPC_URL));

const to = "0x0000000000000000000000000000000000000003";
const from = "0x0000000000000000000000000000000000000001";

// Check if `to` is a delegate of `from` for the entire wallet
console.log(await v2.checkDelegateForAll(to, from));
})();

Outgoing delegations

This example gives permission a the specified to address to act on behalf of the user's account for all contracts on Ronin.

import { custom } from "viem";
import { ronin } from "viem/chains";
import { DelegateV2 } from "@delegatexyz/sdk";
import { WalletSDK } from '@roninnetwork/wallet-sdk'

(async() => {
const sdk = new WalletSDK();
await sdk.connectInjected();
const accounts = await sdk.requestAccounts();

const to = "0x0000000000000000000000000000000000000003";

if(sdk?.getProvider()){
const account = accounts[0];
const v2 = new DelegateV2(custom(sdk.getProvider()), ronin, account);

// Allow `to` to act on behalf of `account` for all contracts
console.log(await v2.delegateAll(to,"",true))
}
})();

See also

Was this page helpful?
Happy React is loading...