Skip to main content

Interact with Delegate.xyz via JS 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 a specified account.

Prerequisites

Installation

npm install @delegatexyz/sdk viem
tip

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

npm install @roninnetwork/wallet-sdk 

Read example

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

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));
})();

Write example

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

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 helpful?
Happy React is loading...