Player Profile
@staratlas/player-profile
Last updated
Was this helpful?
@staratlas/player-profile
Last updated
Was this helpful?
Welcome to the Player Profile, brought to you by Star Atlas! This open protocol empowers developers to seamlessly create and manage decentralized profiles on the Solana blockchain. Dive into a world where game and application profiles are not bound by central control, ensuring greater trust, transparency, and user autonomy.
The Player Profile Program allows users to manage their identity and access keys. Users can create a list of public keys associated with their profile and set permissions for each key. Identity is no longer tied to a key and is instead tied to a profile, allowing for key rotation, complex ownership structures, and more. No CPI is required to check a key that signs on behalf of a profile.
@staratlas/player-profile
TypeScript bindings for the player-profile program
From the Star-Atlas-Cookbook and for https://build.staratlas.com/
TypeScript Code Explanation
This is a TypeScript code example demonstrating how to interact with the Solana blockchain using the @project-serum/anchor and @solana/web3.js libraries. The code fetches player profiles from a Solana account using the readAllFromRPC function.
Importing Libraries
The code imports the following libraries:
@project-serum/anchor
: a library for building Solana applications using TypeScript.
@solana/web3.js
: a library for interacting with the Solana blockchain.
Importing Custom Functions
The code imports custom functions and types:
readAllFromRPC
: a function for reading data from Solana accounts.
PLAYER_PROFILE_IDL
and PlayerProfile
: types related to player profiles.
Importing Shared Functions
The code imports shared functions:
newConnection
and newAnchorProvider
: functions for creating a Solana connection and anchor provider.
loadKeypair
: a function for loading a Keypair from a file.
Constants
The code defines a constant:
PLAYER_PROFILE_PROGRAM_ID
: the ID of the player profile program.
Main Function
The code defines an asynchronous function called main
that takes two arguments:
connection
: a Solana connection.
myWallet
: a Keypair representing the user's wallet.
Creating Provider and Program
The code creates an anchor provider and a program:
provider
: an instance of the newAnchorProvider
function.
playerProfileProgram
: an instance of the Program
class, which is used to interact with the player profile program.
Reading Player Profiles
The code reads all player profiles from the Solana account using the readAllFromRPC
function:
myProfiles
: an array of player profiles.
The memcmp
object is used to filter profiles based on the user's wallet public key.
Handling Player Profiles
The code handles the player profiles:
If no profiles are found, it throws an error.
Otherwise, it logs each profile to the console using JSON.stringify
.
Environment Variables
The code sets environment variables:
wallet
: the path to the user's wallet file.
rpcEndpoint
and rpcWebsocket
: the RPC endpoint and WebSocket URL for interacting with the Solana network.
The code runs the main
function with the created connection and wallet.