UNPKG

@b3dotfun/leaderboards

Version:

SDK to interact with leaderboards smart contract

41 lines 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.exampleUsage = exampleUsage; const viem_1 = require("viem"); const chains_1 = require("viem/chains"); const constants_1 = require("../constants"); const json_abis_1 = require("../json_abis"); // Example of how to use the JSON ABIs with viem async function exampleUsage() { // Create a public client const client = (0, viem_1.createPublicClient)({ chain: chains_1.mainnet, transport: (0, viem_1.http)(constants_1.B3MainnetRpcUrl), }); // Use the LeaderboardFactory ABI to interact with the contract const totalLeaderboards = await client.readContract({ address: constants_1.B3LeaderboardFactoryContractAddress, abi: json_abis_1.LeaderboardFactoryJson, functionName: "getTotalLeaderboardCount", }); console.log(`Total leaderboards: ${totalLeaderboards}`); // Get all leaderboards const leaderboards = await client.readContract({ address: constants_1.B3LeaderboardFactoryContractAddress, abi: json_abis_1.LeaderboardFactoryJson, functionName: "getAllLeaderboards", }); console.log(`Leaderboard addresses: ${leaderboards}`); // If there are any leaderboards, get details of the first one if (Array.isArray(leaderboards) && leaderboards.length > 0) { const firstLeaderboardAddress = leaderboards[0]; // Use the Leaderboard ABI to interact with the leaderboard contract const leaderboardProps = await client.readContract({ address: firstLeaderboardAddress, abi: json_abis_1.LeaderboardJson, functionName: "getLeaderboardProps", }); console.log("Leaderboard properties:", leaderboardProps); } } //# sourceMappingURL=json-abi-usage.js.map