Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Debugging an error? Install the MagicBlock AI skill and ask your coding agent instead.
Solana 链上成就与排名
import { SoarProgram, GameType, Genre } from "@magicblock-labs/soar-sdk"; // 使用 '@solana/web3.js' 的当前 Connection 和默认 defaultPayer 创建 Soar 客户端 const client = SoarProgram.getFromConnection(connection, defaultPayer); let game = Keypair.generate(); let title = "Game1"; let description = "Description"; let genre = Genre.Action; let gameType = GameType.Web; let nftMeta = Keypair.generate().publicKey; let _auths = auths.map((keypair) => keypair.publicKey); // 获取打包后的交易 let { newGame, transaction } = await client.initializeNewGame( game.publicKey, title, description, genre, gameType, nftMeta, _auths ); // 使用 game keypair 作为 signer 发送并确认交易 await web3.sendAndConfirmTransaction(connection, transaction);
const transactionIx = await client.addNewGameLeaderBoard( newGame, authWallet.publicKey, "my leaderboard", // 描述 leaderboardNft, // 与排行榜关联的 nft 100, true // isAscending ); await web3.sendAndConfirmTransaction(connection, transactionIx.transaction, [ authWallet, ]);
const score = 10; const playerAddress = new web3.PublicKey("..."); // 玩家 publicKey const authWallet = web3.Keypair.fromSecretKey(bs58.decode("")); // AUTH_WALLET_PRIVATE_KEY const leaderboardPda = new web3.PublicKey(""); // LEADERBOARD_PDA const transactionIx = await client.submitScoreToLeaderBoard( playerAddress, authWallet.publicKey, leaderboardPda, new BN(score) ); await web3.sendAndConfirmTransaction(connection, transactionIx.transaction, [ authWallet, ]);
SoarProgram
const user = Keypair.generate().publicKey; const playerAddress = client.utils.derivePlayerAddress(user)[0];
const account = await client.fetchLeaderBoardAccount(address);
const accounts = await client.fetchAllLeaderboardAccounts([]);
GameClient
import { GameClient } from "@magicblock-labs/soar-sdk";
const soar = SoarProgram.getFromConnection(connection, defaultPayer); const gameClient = new GameClient(soar, address);
const soar = SoarProgram.getFromConnection(connection, defaultPayer); const game = new GameClient.register(soar, ...);
// 创建一个新的排行榜: await game.addLeaderboard(....); // 访问游戏状态。 await game.init(); // 刷新游戏状态。 await game.refresh(); // 获取某个游戏最近创建的成就 const achievement = game.recentAchievementAddress();
import { InstructionBuilder } from "@magicblock-labs/soar-sdk";
const transaction = await this.builder .andInitializePlayer({ username, nftMeta }, user) .andRegisterPlayerEntry(/*...*/) .andSubmitScoreToLeaderboard(/*...*/) .and(/*some other transaction*/) .then((builder) => builder.build());
此页面对您有帮助吗?