Git Product home page Git Product logo

solana-course's Introduction

Solana Development Course

About

This course is the best place for web developers who are beginning their Web3 development journey. Solana is the ideal network for Web3 because of its high speed, low transaction costs, and large developer community.

The course is currently hosted at https://soldev.app/course.

To learn Solana development using this course, visit Soldev.

Contributing

This is an ongoing, active project, and we'd love for anyone and everyone to contribute! If you'd like to help, look at how you can contribute.

Providing feedback and suggestions

If you have feedback on content or suggestions for additional content, create an issue explaining your feedback/suggestions.

solana-course's People

Contributors

adityakulkarni avatar aheesh avatar bqmackay avatar bunnybites avatar bwnnwtt avatar cdhiraj40 avatar coachchuckff avatar fatimalima avatar gator-rr avatar hmzakhalid avatar ikrk avatar ixmorrow avatar jamesrp13 avatar jeffersonataide avatar johnanthos avatar johnthewhitebelt avatar kimerran avatar longxiaolx avatar loopcreativeandy avatar mebiswajitmalakar avatar mikemaccana avatar mixelpixel avatar mohammedalabd avatar neilshroff avatar nikkaroraa avatar pbillingsby avatar tatkagore avatar thomassimmer avatar zarex5 avatar zyjliu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

solana-course's Issues

Miss-information about data ordering ...

Hello, dear soldev team. i think there is a mistake in section "Data Order" FROM "Dealing with Accounts" subject, that you say you must always place the dynamic variables like Vectors and strings in the end of the Account's data structure to be able to keep track of static variables like ids very easy BUT it really does not matter how to order them for example:

272323300-46814bd0-0f3c-4df7-b5f8-af753a65cddc

#[account]
pub struct Data {
scores: Vec,
id: u8
}

  • In the top example you must specify a static space for your vector, in the account creation time it looks like it is dynamic but in Solana under the hood it is static beacuz the blockchain's space is limited and we have exatcly specify how mush space we want to rent.
    Raw data output for Data's PDA account (with considering10 elements in the vector) :

  • <Buffer ce 9c 3b bc 12 4f f0 e8 03 00 00 00 0a 05 ff 00 00 00 00 00 00 00 01>
    discriminator(8 bytes) + vector-u8(4 + (10 * 1)) + id-u8(1 byte)

  • Memcmp for tracking the "id" section:
    {
    offset: 8 + 14,
    bytes: base58.encode(id)
    }

@jamesrp13

Idea: A voluntary challenge/test at the end of each module

While going from one module to another, a small challenge related to the topic of the module would be a great addition to recapping everything learnt in the chapters. Doesn't need to be compulsory to complete though since experienced folks might just want to skip it.

Which JS borsh library to use?

First off, thank you this great learning resource. It helped me get into Solana more than any other!

My question: should @project-serum/borsh still be used as the default JS borsh library in the course?

I recon that the API of this library is much better (shorter and cleaner) than that of borsh - see example below.

The original Serum organization is dead at this point. The source code of the package is not publicly available. We can't expect any updates to happen in the future (e.g. to swap BN.js for the native bigint) or worse the clear list of accountable maintainer means that an exploit could more easily sneak in. So wouldn't it wiser to now suggest people to use Near's borsh npm package instead?

Alternatively, are you guys aware of another reliable/maintained borsh js client with a nice API?


For ref, the comparison of borsh vs @project-serum/borsh:

import * as sborsh from "@project-serum/borsh";
import * as nborsh from "borsh";
import BN from "bn.js";

// serialization & deserialization of a simple price account with @project-serum/borsh

const priceAccountSchema = sborsh.struct([sborsh.u64("price")]);

const sbuff = Buffer.alloc(8);
priceAccountSchema.encode({ price: new BN("123") }, sbuff);
console.log(sbuff);

const { price } = priceAccountSchema.decode(sbuff);
console.log(`price: ${price}`);

// serialization & deserialization of a simple price account with near's borsh

class PriceAccount {
  price: BN = new BN("0");

  constructor(fields: { price: BN } | undefined = undefined) {
    if (fields) {
      this.price = fields.price;
    }
  }
}

const schema = new Map([
  [
    PriceAccount,
    {
      kind: "struct",
      fields: [["price", "u64"]],
    },
  ],
]);

const nbuffer = Buffer.from(
  nborsh.serialize(schema, new PriceAccount({ price: new BN("123") }))
);
console.log(nbuffer);

const priceData = nborsh.deserialize(schema, PriceAccount, nbuffer);
console.log(`price: ${priceData.price}`);

Transactions should wait till confirmation before resolving.

Newer Solana API versions don't wait till a transaction is confirmed by the cluster before resolving their promises.

The sample solutions provided work due to being on older API versions, but someone following along the course on their may face subsequent transactions failing when they depend on confirmation of the previous transactions.

Module 2-1 for example, throws TokenAccountNotFoundError when run with the latest APIs. Further modules may do so too though I haven't reached them yet.

The connections being created should make sure they're configured to wait till confirmation.

Lesson 5 'initialized' variable

Small issue in Demo section when creating buffer layout where 'initialized' is set as a bool but then switched to u8 with no explanation.

‘Sort’ in M1 Class 7

In M1 Class 7 the ‘Sort’ function isn’t working anymore. I really don’t know why, but it’s seems that getProgramAccount don’t have this command anymore.

I tried to download the source code from git, deleted the package.lock and run ‘npm i install’ and didn’t work too

double spaces & Sentence casing for Demo sections

I think this may be a result of transferring markdown from Notion? I noticed a couple instances of double spaces leading backtick text and am going to do a cross project examination, branch: pdkGlobalFixes

Minting Solana NFTs using Rust

There's already a guide on minting NFTs using candy machine in TS but what if I want to mint NFTs using my program and want to add some custom logic for these NFTs. I will need to make my own anchor program to mint these NFTs,

Support deeplinks for headings

Wanted to link someone to "Use dataSlice to only fetch data you need" and realised we don't have anchor links in headings. We should add them. I can do it.

Screenshot 2023-09-27 at 16 24 34

Portuguese support

heeey @jamesrp13 & folks, I'd like to offer help on translating https://www.soldev.app/course to Portuguese.

should I just adhere to the current content/es-like structure (content/pt), committing it to the draft branch?

I'm thinking about submitting just the texts translations first, due this December, and later on think about translating assets, if that's ok.

let me know your thoughts, have a great week

Starter Codes are already completed

The starter codes mentioned in the course already have the code that is explained in the chapters.

In order to practice and follow the chapter further, I had to first clean up the files that were already created in the repository and then make them again.

Examples here:
Link Provided here.
Screenshot 2022-08-18 at 1 13 55 PM

Module 3.3 - State Management - MovieAccountState struct's fields in wrong order

MovieAccountState struct's fields are in wrong order causing a bug in GUI (description is used as title and vice-versa)

pub struct MovieAccountState {
    pub is_initialized: bool,
    pub rating: u8,
    pub description: String,
    pub title: String
}

should be

pub struct MovieAccountState {
    pub is_initialized: bool,
    pub rating: u8,
    pub title: String,
    pub description: String  
}

Adding initial conext to the course, modules and each chapter

An initial preface to the course, modules and each chapter (TLDR does solve it to an extent) would be great to provide some context on what folks are learning. This would ideally look like:

  • An Introductory video and summary of the course at the start in the table of content
  • Similar video and written introduction at the start of each module
  • A small video walkthrough of each chapter and what folks are about to learn

Module 1.2: Dotenv can't be found, dotenv can

I'm doing Module 1.2 and there's a code snippet that requires importing Dotenv.
For some reason it doesn't work for me until the capital D is replaced by lowercase d.

import web3 = require('@solana/web3.js')
import Dotenv from 'Dotenv'
Dotenv.config()

Error while building program with cargo build-bpf

Screenshot 2022-08-15 at 12 16 32 PM

BPF SDK: /home/ubuntu/.local/share/solana/install/releases/1.10.31/solana-release/bin/sdk/bpf
cargo-build-bpf child: rustup toolchain list -v
cargo-build-bpf child: cargo +bpf build --target bpfel-unknown-unknown --release
/home/ubuntu/.rustup/toolchains/bpf/bin/cargo: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
[package]
name = "sdc"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
no-entrypoint = []

[dependencies]
solana-program = "1.10.31"

[lib]
crate-type = ["cdylib", "lib"]

Incorrect Signer in CPI mint_to Example

Line 353 in content/cpi.md is the PDA signer of the invoke_signed function. This should be the mint aurthority, not the mint address

Currently:

msg!("Minting 10 tokens to User associated token account");
invoke_signed(
    // Instruction
    &spl_token::instruction::mint_to(
        token_program.key,
        token_mint.key,
        user_ata.key,
        mint_auth.key,
        &[],
        10*LAMPORTS_PER_SOL,
    )?,
    // Account_infos
    &[token_mint.clone(), user_ata.clone(), mint_auth.clone()],
    // Seeds
    &[&[b"token_mint", &[mint_bump]]],
)?;

Ok(())

should be:

msg!("Minting 10 tokens to User associated token account");
invoke_signed(
    // Instruction
    &spl_token::instruction::mint_to(
        token_program.key,
        token_mint.key,
        user_ata.key,
        mint_auth.key,
        &[],
        10*LAMPORTS_PER_SOL,
    )?,
    // Account_infos
    &[token_mint.clone(), user_ata.clone(), mint_auth.clone()],
    // Seeds
    &[&[b"token_auth", &[_token_auth_bump]]],
)?;

Ok(())

The underscore has been left on the variable name in this example. Suggest updating lines 293 and 294 to

// Mint tokens here
msg!("deriving mint authority");
let (mint_pda, _mint_bump) = Pubkey::find_program_address(&[b"token_mint"], program_id);
let (mint_auth_pda, mint_auth_bump) =
    Pubkey::find_program_address(&[b"token_auth"], program_id);

Guide on Localnet testing using Amman

Localnet testing speeds up development quite a bit but certain programs are hard to test locally because they use other program deployed on mainnet or devnet like Metaplex's candy machine.

Using Amman we can teach people how to deploy a copy of these program locally so they can test these out on localnet.

Extend clickable / linked area to the entire container

Let me preface this by saying I love what you guys are doing and I'm up to help as much as I can. Grateful for the work you guys put in here

For the course page:

Each section in the module is clickable but only when the text itself is clicked. The cursor changes into a pointer (the one for clicking links) and the container responds by becoming brighter but it's not reacting to the click unless I click directly on the text.

This might be nitpicking, but just wanted to let you guys know it happens.

Do you guys think it would be better to let the entire container clickable and linked to content?

problems module 4 lesson 2

Hey hey I am having issues interacting with the solana programs deployed to devnet with the provided frontends...
I have basically cloned both the solana program and frontend, and i am in the correct branches, changed only program id in the front.
I get the following error with Phantom wallet when creating a review:

Error processing instruction 2
{"code":-32002}

Solfrare is a bit more precise:
{"error":{"logs":["Program AqquXG7sx7JUpycVdQLRGue6imkyYtw8U9w4ZzcDj2gi invoke [1]","Program log: process_instruction: AqquXG7sx7JUpycVdQLRGue6imkyYtw8U9w4ZzcDj2gi: 4 accounts, data=[0, 4, 0, 0, 0, 115, 100, 115, 100, 2, 6, 0, 0, 0, 97, 115, 100, 97, 115, 100]","Program log: Adding movie review...","Program log: Title: sdsd","Program log: Rating: 2","Program log: Description: asdasd","Program AqquXG7sx7JUpycVdQLRGue6imkyYtw8U9w4ZzcDj2gi consumed 25151 of 200000 compute units","Program AqquXG7sx7JUpycVdQLRGue6imkyYtw8U9w4ZzcDj2gi failed: Instruction passed to inner instruction is too large (12884933430 > 1280)"]},"name":"WalletSendTransactionError"}

Please fix it i am enjoying the course so much but it is frustrating to not be able to test my programs!

Minor Typo in Module 2 - 1.

In Section "Token Account" the first sentence says:
"Before you can mint tokens (issue new supply), you need a Token Account to hold the newly issues tokens."

I assume it should be

"Before you can mint tokens (issue new supply), you need a Token Account to hold the newly issued tokens."

Adding Proof-of-Completion at the end of each chapter

Would be good to have a section to attach a screenshot/GitHub Repo Link of the challenge or demo of that particular chapter in order to move to the next one instead of just ticking off the chapter manually. This would create accountability and ensure the completion of the challenges in the process of learning.

Course Chapter 1, Page 3 has unclear and not correct code example #44

I am talking about this page: https://www.soldev.app/course/intro-to-writing-data

In the Lab section, you can find the following code example which I annotated with comments where I think the block could be improved:

import * as web3 from "@solana/web3.js";
import * as dotenv from "dotenv";
import base58 from "bs58"; // not actually used here (neither in the next block), can be removed
import { getKeypairFromEnvironment } from "@solana-developers/node-helpers"
const toPubkey = new PublicKey(suppliedToPubkey); // suppliedToPubkey is nowhere defined. Maybe show an example with a generated pub key here as in the first tutorial

dotenv.config(); // with es module syntax, it's actually better to just import dotenv/config

const senderKeypair = getKeypairFromEnvironment("SECRET_KEY");

const connection = new Connection("https://api.devnet.solana.com", "confirmed");


console.log(`✅ Loaded our own keypair, the destination public key, and connected to Solana`);

This is what I would suggest the code to update to:

import "dotenv/config"
import { Connection, clusterApiUrl, Keypair } from "@solana/web3.js"
import { getKeypairFromEnvironment } from "@solana-developers/node-helpers"

const { publicKey: toPubkey } = new Keypair()
const senderKeypair = getKeypairFromEnvironment("SECRET_KEY")

const connection = new Connection(clusterApiUrl("devnet"))

console.log(
  `✅ Loaded our own keypair, the destination public key, and connected to Solana`,
)

The original code block on the website is actually not working at all. You import * as web3 from "@solana/web3.js" and then use the PublicKey constructor directly, which is not possible. Instead you would have to call the constructor like this: new web3.PublicKey(suppliedToPubkey).

Markdown backticks not rendering on soldev.app

Markdown backticks are not rendering on soldev.app. From https://github.com/Unboxed-Software/solana-course/blob/main/content/hello-world-program.md:

The path to a particular module or item is the name of each step from the crate to that module where each is separated by `::`. As an example, let's look at the following structure:

1. The base crate is `solana_program`
2. `solana_program` contains a module named `account_info`
3. `account_info` contains a struct named `AccountInfo`

The path to `AccountInfo` would be `solana_program::account_info::AccountInfo`.

Is rendered ignoring backticks, eg from https://www.soldev.app/course/hello-world-program:

Screenshot 2023-07-11 at 16 21 38

It should look like:

Screenshot 2023-07-11 at 16 23 48

The fix

It looks like the .inline-code class is missing a font-family declaration. Would fix this myself but there's no info about how the course in rendered in the README and I can't find info on how the rendered version is built.

Error in Code (Intro to Writing Data)

Relevant page - https://www.soldev.app/course/intro-to-writing-data

In Step 1 of the Lab section we use the following code to import Keypair from web3.js

import { Keypair } from "@solana/web3.js";

But, in the later lines of code we use the variable 'web3' in the following line:

const connection = new web3.Connection(web3.clusterApiUrl('devnet'))

But there is no variable web3 defined. Hence the following line must be included instead of the first code I provided here:

import * as web3 from "@solana/web3.js";

Bad import syntax in Intro to Solana 1.3

This is a snippet taken from the course

import { NextPage } from 'next';
import { FC, ReactNode } from 'react';
import { ConnectionProvider, WalletProvider } from '@solana/wallet-adapter-react';
import { PhantomWalletAdapter } from '@solana/wallet-adapter-phantom';
import web3 from '@solana/web3.js';

export const Home: NextPage = props => {
  const endpoint = web3.clusterApiUrl('devnet');
  const wallet = new PhantomWalletAdapter();

  return (
    <ConnectionProvider endpoint={endpoint}>
      <WalletProvider wallets={[wallet]}>
        <p>Put the rest of your app here</p>
      </WalletProvider>
    </ConnectionProvider>
  );
};

however, when run like this, it creates an error:
image

web3 should be imported like import * as web3 from "solana/web3.js" instead to work properly.

Adding support for other sol wallets

We can only connect a phantom wallet right now, and I don't use a phantom lol.
Its quite easy to add support for most of the commonly used wallets like solflare and others, just need to add a few lines to the frontend. Will change it in a PR if you like

Module 3.4 - Create a Basic Program, Part 3 - Basic Security and Validation - typo/inconsistency in description

The section describing Ownership checks mentions that the note-taking app is the focus. However, in the next section, the first sentence talks about movie review apps. See directly cited text from module description below - inconsistency in italic/bold text:

Ownership checks
An ownership check verifies that an account is owned by the expected public key. Let's use the note-taking app example that we've referenced in previous lessons. In this app, users can create, update, and delete notes that are stored by the program in PDA accounts.
When a user invokes the update instruction, they also provide a pda_account. We presume the provided pda_account is for the particular movie review they want to update, but the user can input any instruction data they want. They could even potentially send data which matches the data format of a note account but was not also created by the note-taking program. This security vulnerability is one potential way to introduce malicious code.

Cargo build-bpf doesnt compile due to openssl issue

BPF SDK: /home/ubuntu/.local/share/solana/install/releases/1.10.31/solana-release/bin/sdk/bpf
cargo-build-bpf child: rustup toolchain list -v
cargo-build-bpf child: cargo +bpf build --target bpfel-unknown-unknown --release
/home/ubuntu/.rustup/toolchains/bpf/bin/cargo: /lib/x86_64-linux-gnu/libssl.so.1.1: version `OPENSSL_1_1_1' not found (required by /home/ubuntu/.rustup/toolchains/bpf/bin/cargo)
/home/ubuntu/.rustup/toolchains/bpf/bin/cargo: /lib/x86_64-linux-gnu/libcrypto.so.1.1: version `OPENSSL_1_1_1' not found (required by /home/ubuntu/.rustup/toolchains/bpf/bin/cargo)

Trying https://soldev.app/course/local-setup in ec2 instance ubuntu instance and i get this error

Add reminder to check branch for starter/solution code

Everywhere there's mention of starter code/solution code with a link, we should add a reminder that if the clone the repo they'll need to change the branch to the corresponding branch (e.g. starter if they want starter code, solution if they want solution code). The links go to the right branch, but if you clone it then your local repo will default to the main branch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.