Solana Curriculum - Error in Terminal

issue with my code :
main.js


helloworld.js


cli :

Error [ERR_MODULE_NOT_FOUND]: Cannot find module ‘/workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/src/client/helloworld’ imported from /workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/src/client/main.js
at new NodeError (node:internal/errors:405:5)
at finalizeResolution (node:internal/modules/esm/resolve:324:11)
at moduleResolve (node:internal/modules/esm/resolve:943:10)
at defaultResolve (node:internal/modules/esm/resolve:1129:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap. (node:internal/modules/esm/module_job:77:40)
at link (node:internal/modules/esm/module_job:76:36) {
code: ‘ERR_MODULE_NOT_FOUND’
}

Hello there,

You have a syntax error in your hello-world.js file. Fix this, and that error should be gone.

For future posts, please do not paste pictures of code, but format your code:

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like

terminal :


root@bd9f085b553e:~/solana-curriculum/learn-how-to-interact-with-on-chain-programs# node src/client/main.js
Saying 'hello' to a Solana account
/workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/node_modules/@solana/web3.js/lib/index.cjs.js:9560
      throw new SendTransactionError('failed to send transaction: ' + res.error.message, logs);
            ^

SendTransactionError: failed to send transaction: Transaction simulation failed: Attempt to debit an account but found no record of a prior credit.
    at Connection.sendEncodedTransaction (/workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/node_modules/@solana/web3.js/lib/index.cjs.js:9560:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Connection.sendRawTransaction (/workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/node_modules/@solana/web3.js/lib/index.cjs.js:9526:20)
    at async Connection.sendTransaction (/workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/node_modules/@solana/web3.js/lib/index.cjs.js:9517:12)
    at async sendAndConfirmTransaction (/workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/node_modules/@solana/web3.js/lib/index.cjs.js:2145:21)
    at async createAccount (file:///workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/src/client/hello-world.js:80:5)
    at async checkProgram (file:///workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/src/client/hello-world.js:55:9)
    at async main (file:///workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/src/client/main.js:12:5)
    at async file:///workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/src/client/main.js:18:1 {
  logs: []
}

Node.js v18.17.1

code :
main.js

import { establishConnection, getProgramId, establishPayer, checkProgram, sayHello, getHelloCount, getAccountPubkey } from "./hello-world.js";



async function main() {
    const connection = establishConnection();
    console.log("Saying 'hello' to a Solana account");

    const programId = await getProgramId();
    const payer = await establishPayer();
    const accountPubkey = await getAccountPubkey(payer, programId);
    await checkProgram(connection, payer, programId, accountPubkey);
    await sayHello(connection, payer, programId, accountPubkey);
    const helloCount = await getHelloCount(connection, accountPubkey);
    console.log(helloCount);

  }
await main()

helloworld.js

//import { PublicKey } from "@metaplex-foundation/js";
import { Connection, PublicKey, Keypair, Transaction, TransactionInstruction, sendAndConfirmTransaction, SystemProgram } from "@solana/web3.js";
import { readFile } from "fs/promises"
import * as borsh from 'borsh';


class HelloWorldAccount {
    constructor(fields) {
        if (fields) {
            this.counter = fields.counter;
        }else {
            this.counter = 0;
        }
    }
} 

const HelloWorldSchema = new Map([
    [HelloWorldAccount, { kind: 'struct', fields: [['counter', 'u32']] }]
]);

const ACCOUNT_SIZE = borsh.serialize(HelloWorldSchema, new HelloWorldAccount()).length;

export function establishConnection() {
    const connection = new Connection('http://localhost:8899');
    return connection;
}

export async function establishPayer(connection) {
    let secretKeyString = await readFile("../../../workspace/.config/solana/id.json", 'utf-8');
    let secretKey = Uint8Array.from(JSON.parse(secretKeyString));
    return Keypair.fromSecretKey(secretKey);
}

export async function getProgramId() {
    let secretKeyString = await readFile("dist/program/helloworld-keypair.json", 'utf8');
    let secretKey = Uint8Array.from(JSON.parse(secretKeyString));
    let keypair = Keypair.fromSecretKey(secretKey);
    return keypair.publicKey;
}

export async function getAccountPubkey(payer, programId) {
    return await PublicKey.createWithSeed(payer.publicKey, "ntg", programId);
}

export async function checkProgram(connection, payer, programId, accountPubkey) {
    const accountInfo =  await connection.getAccountInfo(programId);
    
    if (accountInfo === null) {

        throw new Error('Program account not found');
    }
    const dataAccountInfo = await connection.getAccountInfo(accountPubkey);

    if (dataAccountInfo === null) {
        await createAccount(connection, payer, programId, accountPubkey);
    }
    if (!accountInfo.executable) {
        throw new Error('Program account is not executable');
    }

    return accountInfo;
}

export async function createAccount(connection, payer, programId, accountPubkey) {
    let lamports = await connection.getMinimumBalanceForRentExemption(ACCOUNT_SIZE);

    const instruction = {
        basePubkey: payer.publicKey,
        fromPubkey: payer.publicKey,
        lamports,
        newAccountPubkey: accountPubkey,
        programId,
        seed : "ntg",
        space : ACCOUNT_SIZE,
    };
    const tx = SystemProgram.createAccountWithSeed(instruction);

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

export async function sayHello(connection, payer, programId, accountPubkey) {
    const transaction = {
        keys: [{ pubkey: accountPubkey, isSigner: false, isWritable: true}],
        programId,
        data: Buffer.alloc(0),
    }
    const instruction = new TransactionInstruction(transaction);
    await sendAndConfirmTransaction(connection, new Transaction().add(instruction), [payer]);
}

export async function getHelloCount(connection, accountPubkey) {
    const accountInfo = await connection.getAccountInfo(accountPubkey);
    const greeting = borsh.deserialize(HelloWorldSchema, HelloWorldAccount, accountInfo.data);
    return greeting.counter;


}

iam not able to found the mistake in y code and
the newly generated key pair is stored in /workspace/.config/solana directory

this the terminal output from 52 -54 lesson :


root@bd9f085b553e:~/solana-curriculum/learn-how-to-interact-with-on-chain-programs# solana-keygen new --force
Generating a new keypair

For added security, enter a BIP39 passphrase

NOTE! This passphrase improves security of the recovery seed phrase NOT the
keypair file itself, which is stored as insecure plain text

BIP39 Passphrase (empty for none): 

Wrote new keypair to /workspace/.config/solana/id.json
===============================================================================
pubkey: 7aeaNDQSsPKFtN27XKAxgmdMAPZpoE34HPMpKvDcEeEr
===============================================================================
Save this seed phrase and your BIP39 passphrase to recover your new keypair:
blanket vocal artist perfect crop powder nerve planet yellow expand over answer
===============================================================================
root@bd9f085b553e:~/solana-curriculum/learn-how-to-interact-with-on-chain-programs# solana program deploy dist/program/helloworld.so               
Error: Program's authority Some(DNuzwAFdb9JHgFp5EaHtv4nLyGpyWvczuFHjqpinLtVC) does not match authority provided 7aeaNDQSsPKFtN27XKAxgmdMAPZpoE34HPMpKvDcEeEr
root@bd9f085b553e:~/solana-curriculum/learn-how-to-interact-with-on-chain-programs# cd src/program-rust/
root@bd9f085b553e:~/solana-curriculum/learn-how-to-interact-with-on-chain-programs/src/program-rust# cargo build-bpf --bpf-out-dir=../../dist/program
    Finished release [optimized] target(s) in 0.47s
root@bd9f085b553e:~/solana-curriculum/learn-how-to-interact-with-on-chain-programs/src/program-rust# cd ../..
root@bd9f085b553e:~/solana-curriculum/learn-how-to-interact-with-on-chain-programs# solana program deploy dist/program/helloworld.so
Error: Program's authority Some(DNuzwAFdb9JHgFp5EaHtv4nLyGpyWvczuFHjqpinLtVC) does not match authority provided 7aeaNDQSsPKFtN27XKAxgmdMAPZpoE34HPMpKvDcEeEr
root@bd9f085b553e:~/solana-curriculum/learn-how-to-interact-with-on-chain-programs# 


root@bd9f085b553e:~/solana-curriculum/learn-how-to-interact-with-on-chain-programs# node src/client/main.js        
Saying 'hello' to a Solana account
/workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/node_modules/@solana/web3.js/lib/index.cjs.js:9560
      throw new SendTransactionError('failed to send transaction: ' + res.error.message, logs);
            ^

SendTransactionError: failed to send transaction: Transaction simulation failed: Attempt to debit an account but found no record of a prior credit.
    at Connection.sendEncodedTransaction (/workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/node_modules/@solana/web3.js/lib/index.cjs.js:9560:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Connection.sendRawTransaction (/workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/node_modules/@solana/web3.js/lib/index.cjs.js:9526:20)
    at async Connection.sendTransaction (/workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/node_modules/@solana/web3.js/lib/index.cjs.js:9517:12)
    at async sendAndConfirmTransaction (/workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/node_modules/@solana/web3.js/lib/index.cjs.js:2145:21)
    at async createAccount (file:///workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/src/client/hello-world.js:82:5)
    at async checkProgram (file:///workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/src/client/hello-world.js:57:9)
    at async main (file:///workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/src/client/main.js:12:5)
    at async file:///workspace/solana-curriculum/learn-how-to-interact-with-on-chain-programs/src/client/main.js:18:1 {
  logs: []
}

Node.js v18.17.1
root@bd9f085b553e:~/solana-curriculum/learn-how-to-interact-with-on-chain-programs# 

logs :


🔴 ERROR:  2023-11-23 12:47:47 Test #2: [Error: ENOENT: no such file or directory, scandir '/root/.config/solana'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'scandir',
  path: '/root/.config/solana'
}
🔵 INFO:  2023-11-23 12:59:15 Watching for file changes on /workspace/solana-curriculum
🔴 ERROR:  2023-11-23 12:59:28 Test #2: Error: Could not find /workspace/solana-curriculum/.logs/.cwd.log
    at Object.getCWD (file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/test-utils.js:133:11)
    at async eval (eval at <anonymous> (file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/test.js:107:37), <anonymous>:1:31)
    at async file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/test.js:107:31
    at async Promise.allSettled (index 1)
    at async runTests (file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/test.js:145:19)
    at async Object.handleRunTests [as run-tests] (file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/server.js:68:3)
🔴 ERROR:  2023-11-23 12:59:38 Test #2: Error: Could not find /workspace/solana-curriculum/.logs/.cwd.log
    at Object.getCWD (file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/test-utils.js:133:11)
    at async eval (eval at <anonymous> (file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/test.js:107:37), <anonymous>:1:31)
    at async file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/test.js:107:31
    at async Promise.allSettled (index 1)
    at async runTests (file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/test.js:145:19)
    at async Object.handleRunTests [as run-tests] (file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/server.js:68:3)
🔴 ERROR:  2023-11-23 13:00:05 Test #2: Error: Could not find /workspace/solana-curriculum/.logs/.cwd.log
    at Object.getCWD (file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/test-utils.js:133:11)
    at async eval (eval at <anonymous> (file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/test.js:107:37), <anonymous>:1:31)
    at async file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/test.js:107:31
    at async Promise.allSettled (index 1)
    at async runTests (file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/test.js:145:19)
    at async Object.handleRunTests [as run-tests] (file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/server.js:68:3)
🔴 ERROR:  2023-11-23 13:02:27 Test #2: [Error: ENOENT: no such file or directory, scandir '/root/.config/solana'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'scandir',
  path: '/root/.config/solana'
}
🔴 ERROR:  2023-11-23 13:02:35 Test #2: Error: Could not find /workspace/solana-curriculum/.logs/.cwd.log
    at Object.getCWD (file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/test-utils.js:133:11)
    at async eval (eval at <anonymous> (file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/test.js:107:37), <anonymous>:1:31)
    at async file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/test.js:107:31
    at async Promise.allSettled (index 1)
    at async runTests (file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/test.js:145:19)
    at async Object.handleRunTests [as run-tests] (file:///workspace/solana-curriculum/node_modules/@freecodecamp/freecodecamp-os/.freeCodeCamp/tooling/server.js:68:3)

hey this command worked for me to over write the key-pair in respective .json file :

solana-keygen new --force --outfile dist/program/helloworld-keypair.json

Include these after new key generation


root@bd9f085b553e:~/solana-curriculum/learn-how-to-interact-with-on-chain-programs# solana-keygen new --force --outfile dist/program/helloworld-keypair.json
Generating a new keypair

For added security, enter a BIP39 passphrase

NOTE! This passphrase improves security of the recovery seed phrase NOT the
keypair file itself, which is stored as insecure plain text

BIP39 Passphrase (empty for none): 

Wrote new keypair to dist/program/helloworld-keypair.json
==========================================================================
pubkey: FAJF623LJ8G6zyKPMPayMj6XsQR5PcrkMwwNq4BvMmx2
==========================================================================
Save this seed phrase and your BIP39 passphrase to recover your new keypair:
champion treat genre truly bronze race lunch bargain typical hip allow gap
==========================================================================
root@bd9f085b553e:~/solana-curriculum/learn-how-to-interact-with-on-chain-programs# solana program deploy dist/program/helloworld.so
==============================================================================
Recover the intermediate account's ephemeral keypair file with
`solana-keygen recover` and the following 12-word seed phrase:
==============================================================================
giggle lecture wagon company valid bird person still rabbit height seat square
==============================================================================
To resume a deploy, pass the recovered keypair as the
[BUFFER_SIGNER] to `solana program deploy` or `solana program write-buffer'.
Or to recover the account's lamports, pass it as the
[BUFFER_ACCOUNT_ADDRESS] argument to `solana program close`.
==============================================================================
Error: Account 7aeaNDQSsPKFtN27XKAxgmdMAPZpoE34HPMpKvDcEeEr has insufficient funds for spend (0.66669144 SOL) + fee (0.00026 SOL)
root@bd9f085b553e:~/solana-curriculum/learn-how-to-interact-with-on-chain-programs# solana airdrop 50
Requesting airdrop of 50 SOL

Signature: 5mHAaMDg9WK67zJ7FfR122EdjJGpvDqEvDr2eFPYdmhNbLbb1uBgNTKpwVZBbD2WYXEgeQyLHjJpNrTGyvEGvoXq

50 SOL
root@bd9f085b553e:~/solana-curriculum/learn-how-to-interact-with-on-chain-programs# solana program deploy dist/program/helloworld.so                        
Program Id: FAJF623LJ8G6zyKPMPayMj6XsQR5PcrkMwwNq4BvMmx2

root@bd9f085b553e:~/solana-curriculum/learn-how-to-interact-with-on-chain-programs# node src/client/main.js
Saying 'hello' to a Solana account
1
root@bd9f085b553e:~/solana-curriculum/learn-how-to-interact-with-on-chain-programs# node src/client/main.js
Saying 'hello' to a Solana account
2
root@bd9f085b553e:~/solana-curriculum/learn-how-to-interact-with-on-chain-programs# 

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.