Skip to main content
Code formatting.
Source Link
steveluscher
  • 3.2k
  • 8
  • 38

Looks like they did not include the creation of the counter in the program but instead are handling it on the Client side using System Program. Take a look at the tests:

const allocIx: TransactionInstruction = SystemProgram.createAccount({
            fromPubkey: payer,
            newAccountPubkey: counter,
            lamports: await connection.getMinimumBalanceForRentExemption(COUNTER_ACCOUNT_SIZE),
            space: COUNTER_ACCOUNT_SIZE,
            programId: PROGRAM_ID
        })
const allocIx: TransactionInstruction = SystemProgram.createAccount({
  fromPubkey: payer,
  newAccountPubkey: counter,
  lamports: await connection.getMinimumBalanceForRentExemption(
    COUNTER_ACCOUNT_SIZE
  ),
  space: COUNTER_ACCOUNT_SIZE,
  programId: PROGRAM_ID,
});

This is a little different than how they've implemented in the anchor example, where they've explicitly created an initialize function in the program:

pub fn initialize_counter(_ctx: Context<InitializeCounter>) -> Result<()> {
    Ok(())
}

Looks like they did not include the creation of the counter in the program but instead are handling it on the Client side using System Program. Take a look at the tests:

const allocIx: TransactionInstruction = SystemProgram.createAccount({
            fromPubkey: payer,
            newAccountPubkey: counter,
            lamports: await connection.getMinimumBalanceForRentExemption(COUNTER_ACCOUNT_SIZE),
            space: COUNTER_ACCOUNT_SIZE,
            programId: PROGRAM_ID
        })

This is a little different than how they've implemented in the anchor example, where they've explicitly created an initialize function in the program:

pub fn initialize_counter(_ctx: Context<InitializeCounter>) -> Result<()> {
    Ok(())
}

Looks like they did not include the creation of the counter in the program but instead are handling it on the Client side using System Program. Take a look at the tests:

const allocIx: TransactionInstruction = SystemProgram.createAccount({
  fromPubkey: payer,
  newAccountPubkey: counter,
  lamports: await connection.getMinimumBalanceForRentExemption(
    COUNTER_ACCOUNT_SIZE
  ),
  space: COUNTER_ACCOUNT_SIZE,
  programId: PROGRAM_ID,
});

This is a little different than how they've implemented in the anchor example, where they've explicitly created an initialize function in the program:

pub fn initialize_counter(_ctx: Context<InitializeCounter>) -> Result<()> {
    Ok(())
}
Backlinked to Github repo and added code snippets directly
Source Link

Looks like they did not include the creation of the counter in the program but instead are handling it on the Client side using System Program. Take a look at the tests:

https://github.com/solana-developers/program-examples/blob/d6cd69d8df3eb95966b3d2361ede84529413567a/basics/counter/native/tests/counter.test.ts#L37C8-L43the tests:

const allocIx: TransactionInstruction = SystemProgram.createAccount({
            fromPubkey: payer,
            newAccountPubkey: counter,
            lamports: await connection.getMinimumBalanceForRentExemption(COUNTER_ACCOUNT_SIZE),
            space: COUNTER_ACCOUNT_SIZE,
            programId: PROGRAM_ID
        })

This is a little different than how they've implemented in the anchor examplein the anchor example, where they've explicitly created an initialize function in the program: https://github.com/solana-developers/program-examples/blob/d6cd69d8df3eb95966b3d2361ede84529413567a/basics/counter/anchor/programs/counter_anchor/src/lib.rs#L11-L13

pub fn initialize_counter(_ctx: Context<InitializeCounter>) -> Result<()> {
    Ok(())
}

Looks like they did not include the creation of the counter in the program but instead are handling it on the Client side using System Program. Take a look at the tests:

https://github.com/solana-developers/program-examples/blob/d6cd69d8df3eb95966b3d2361ede84529413567a/basics/counter/native/tests/counter.test.ts#L37C8-L43

This is a little different than how they've implemented in the anchor example, where they've explicitly created an initialize function in the program: https://github.com/solana-developers/program-examples/blob/d6cd69d8df3eb95966b3d2361ede84529413567a/basics/counter/anchor/programs/counter_anchor/src/lib.rs#L11-L13

Looks like they did not include the creation of the counter in the program but instead are handling it on the Client side using System Program. Take a look at the tests:

const allocIx: TransactionInstruction = SystemProgram.createAccount({
            fromPubkey: payer,
            newAccountPubkey: counter,
            lamports: await connection.getMinimumBalanceForRentExemption(COUNTER_ACCOUNT_SIZE),
            space: COUNTER_ACCOUNT_SIZE,
            programId: PROGRAM_ID
        })

This is a little different than how they've implemented in the anchor example, where they've explicitly created an initialize function in the program:

pub fn initialize_counter(_ctx: Context<InitializeCounter>) -> Result<()> {
    Ok(())
}
Source Link
AMilz
  • 1.9k
  • 3
  • 11

Looks like they did not include the creation of the counter in the program but instead are handling it on the Client side using System Program. Take a look at the tests:

https://github.com/solana-developers/program-examples/blob/d6cd69d8df3eb95966b3d2361ede84529413567a/basics/counter/native/tests/counter.test.ts#L37C8-L43

This is a little different than how they've implemented in the anchor example, where they've explicitly created an initialize function in the program: https://github.com/solana-developers/program-examples/blob/d6cd69d8df3eb95966b3d2361ede84529413567a/basics/counter/anchor/programs/counter_anchor/src/lib.rs#L11-L13