DeveloperBreeze

Solana Development Tutorials, Guides & Insights

Unlock 7+ expert-curated solana tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your solana skills on DeveloperBreeze.

Using Solana's Program Library: Building Applications with Pre-Built Functions

Tutorial August 27, 2024
rust

To interact with your newly deployed program, you can write a simple client script in Rust or JavaScript using Solana's web3.js library. Here's an example using JavaScript:

const {
    Connection,
    PublicKey,
    clusterApiUrl,
    Keypair,
    TransactionInstruction,
    sendAndConfirmTransaction,
} = require('@solana/web3.js');
const { Token, TOKEN_PROGRAM_ID } = require('@solana/spl-token');

// Add your connection, payer, and mint keypair
const connection = new Connection(clusterApiUrl('devnet'), 'confirmed');
const payer = Keypair.fromSecretKey(...); // Replace with your payer keypair
const mint = new PublicKey('Your Mint Public Key');

async function mintToken() {
    const tokenAccount = await Token.getAssociatedTokenAddress(
        mint,
        payer.publicKey
    );

    const instruction = new TransactionInstruction({
        keys: [{ pubkey: tokenAccount, isSigner: false, isWritable: true }],
        programId: TOKEN_PROGRAM_ID,
        data: Buffer.from([]),
    });

    const transaction = await sendAndConfirmTransaction(
        connection,
        new Transaction().add(instruction),
        [payer]
    );

    console.log('Minted token:', transaction);
}

mintToken();

Tracking Solana Address for New Trades and Amounts

Tutorial August 09, 2024
javascript nodejs

Step 1: Set Up Your Project

   mkdir solana-address-tracker
   cd solana-address-tracker

Tracking Newly Created Tokens on Solana

Tutorial August 09, 2024
javascript nodejs

Step 2: Connect to the Solana Network

Create a new file called index.js and add the following code to connect to the Solana blockchain:

Fetching Address Details from Solana

Tutorial August 09, 2024
javascript json

This function uses the getParsedTokenAccountsByOwner method to retrieve token accounts owned by the wallet address. It then logs the token mint address and the amount held.

Conclusion

Building a Simple Solana Smart Contract with Anchor

Tutorial August 09, 2024
javascript bash rust nodejs

   const anchor = require("@project-serum/anchor");

   describe("counter", () => {
     // Configure the client to use the local cluster.
     const provider = anchor.AnchorProvider.env();
     anchor.setProvider(provider);

     it("Initializes and increments the counter", async () => {
       const program = anchor.workspace.Counter;

       // Create a new account to hold the counter state.
       const counter = anchor.web3.Keypair.generate();

       // Initialize the counter.
       await program.rpc.initialize({
         accounts: {
           counter: counter.publicKey,
           user: provider.wallet.publicKey,
           systemProgram: anchor.web3.SystemProgram.programId,
         },
         signers: [counter],
       });

       // Increment the counter.
       await program.rpc.increment({
         accounts: {
           counter: counter.publicKey,
         },
       });

       // Fetch the account details.
       const account = await program.account.counter.fetch(counter.publicKey);
       console.log("Count:", account.count.toString());
     });
   });

Use the following command to run the test and interact with your contract: