Git Product home page Git Product logo

program-examples's Issues

Where can I ask questions about these examples?

Hi:

I am trying to understand the examples in this repo. While I have reasonable understanding of writing Solidity code for EVM targets, some of the code in the examples is hard for me to understand. For example, in this:

@program_id("F1ipperKF9EfD821ZbbYjS319LXYiBmjhzkkf5a26rC")
contract hello_solana {
    // The constructor is used to create a new account
    // Here we create a new account that stores no data and only prints messages to the program logs when the constructor is called.
    @payer(payer) // The "payer" pays for the account creation
    constructor() {
        // We get the program ID by calling 'this';
        address programId = address(this);

        // Print messages to the program logs
        print("Hello, Solana!");
        print("Our program's Program ID: {:}".format(programId));
    }
}

What is the meaning of @program_id and how is the value F1ipperKF9EfD821ZbbYjS319LXYiBmjhzkkf5a26rC generated or discovered?

Also, what is @payer(payer) about? I have not run across this before in typical Solidity programming for the EVM.

I know these are newbie questions, maybe not appropriate for this issue. If so, please might you be able to tell me where I can get some questions answered?

Thanks in advance!

Can't execute a Solana program compiled from Solidity code with Solang

Hi:

I am trying to exercise a Solana program I migrated from Solidity using Solang.

I keep getting this error:

Error: SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: invalid program argument
    at Connection.sendEncodedTransaction (/home/reselbob/Documents/solidity-to-solana/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 (/home/reselbob/Documents/solidity-to-solana/node_modules/@solana/web3.js/lib/index.cjs.js:9526:20)
    at async Connection.sendTransaction (/home/reselbob/Documents/solidity-to-solana/node_modules/@solana/web3.js/lib/index.cjs.js:9517:12)
    at async sendAndConfirmTransaction (/home/reselbob/Documents/solidity-to-solana/node_modules/@solana/web3.js/lib/index.cjs.js:2145:21)
    at async callGetMessage (/home/reselbob/Documents/solidity-to-solana/scripts/SayHi.js:50:20) {
  logs: [
    'Program 5FWPj98F4TEfSvWxqYXQW4whdoLXTN2yeXfCJWfY7EjL invoke [1]',
    'Program 5FWPj98F4TEfSvWxqYXQW4whdoLXTN2yeXfCJWfY7EjL consumed 34 of 200000 compute units',
    'Program 5FWPj98F4TEfSvWxqYXQW4whdoLXTN2yeXfCJWfY7EjL failed: invalid program argument'
  ]
}

I demonstrate the issue in this 4 minute video.

For purposes of research, I am intentionally avoiding using Anchor.

Here is the Solidity code that I migrated.

Here is the client script I used to try to execute the program.

Here is the entire project on GitHub.

If the problem is due to some mistake on my part, in all sincerity I ask your forgiveness.

For what it's worth, this problem has been plaguing me for days.

Thanks in advance for any help and direction you can provide.

Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Cross-program invocation with unauthorized signer or writable account

Hello there,
Please I have this bug i have been facing, i have tried everything but it’s not working
this is the raw error message
Error: Raw transaction 4n7GkQVEtedpvjMU27nnfhwxJhXh6xHxCG7VV8taVtdhvEyo7BfEdkctX84zx3CEvxxFCYCLEbPiFPKzB9AsEuXi failed ({"err":{"InstructionError":[0,"PrivilegeEscalation"]}})

Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Cross-program invocation with unauthorized signer or writable account

Please here is my code, i will really appreciate it of anyone can help

Screenshot 2023-09-07 at 14 54 10

And here is my test code below
Screenshot 2023-09-07 at 14 54 20
Screenshot 2023-09-07 at 14 54 31

I can not run "favorites" example

When I run basics/favorites/anchor project, there is error like below.
Could you tell me how to fix this?
Thanks in advance

favorites
Balance: 500,000,000 SOL
1) Writes our favorites to the blockchain
Invalid arguments: favorites not provided.
2) Updates the favorites
3) Rejects transactions from unauthorized signers

0 passing (301ms)
3 failing

  1. favorites
    Writes our favorites to the blockchain:
    Error: Invalid arguments: favorites not provided.
    at /home/quan/workspace/favorites/node_modules/@coral-xyz/anchor/src/program/common.ts:50:15
    at Array.forEach ()
    at validateAccounts (node_modules/@coral-xyz/anchor/src/program/common.ts:45:14)
    at ix (node_modules/@coral-xyz/anchor/src/program/namespace/instruction.ts:44:23)
    at txFn (node_modules/@coral-xyz/anchor/src/program/namespace/transaction.ts:24:14)
    at MethodsBuilder.rpc [as _rpcFn] (node_modules/@coral-xyz/anchor/src/program/namespace/rpc.ts:21:18)
    at MethodsBuilder.rpc (node_modules/@coral-xyz/anchor/src/program/namespace/methods.ts:212:17)

  2. favorites
    Updates the favorites:
    Error: null
    at /home/quan/workspace/favorites/tests/favorites.ts:60:13
    at Generator.throw ()
    at rejected (tests/favorites.ts:29:65)

  3. favorites
    Rejects transactions from unauthorized signers:

    AssertionError: expected false to be true

    • expected - actual

    -false
    +true

    at /home/quan/workspace/favorites/tests/favorites.ts:75:14
    at Generator.throw ()
    at rejected (tests/favorites.ts:29:65)

Add CI/CD

It would be nice to have a setup where the example programs can be deployed and the client tests ran against them. I think it should be possible to set this up with github actions.

If this is considered worth having, then I will be happy to help setup.

Overflow issue in swap ?

Why does the token-swap use whole u64 amounts in the following I64F64 calculation - which in my view could lead to overflow issues. The maximum Integer part from I6F64 is 2^63 -1. In their deposit_liquidity.rs file they calculated liquidity like:

pub fn deposit_liquidity(
    ctx: Context<DepositLiquidity>,
    amount_a: u64,
    amount_b: u64,
) -> Result<()> {
...
    let mut liquidity = I64F64::from_num(amount_a)
            .checked_mul(I64F64::from_num(amount_b))
            .unwrap()
            .sqrt()
            .to_num::<u64>();

That means if for example amount_a and amount_b is give in lamports which is sol * 10^9 they could only provide the square root of (2^63 - 1) / 10^9 = 3 SOL into the contract on each side. Why not cut amount/10^9 before the calculations as I64F64 has its floating precision also set to 2^-64 . Meaning, the overflow issue isnt a problem if the arguments are lamports - great for precision. But why don't they convert and calculate in SOL / use U128F0 within the contract? Or am I misunderstanding something here ?

Why token swap only works in devnet?

If update the anchor.toml to localnet

[programs.localnet]
swap_example = "C3ti6PFK6PoYShRFx1BNNTQU3qeY1iVwjwCA6SjJhiuW"

[provider]
cluster = "Localnet"
wallet = "~/.config/solana/id.json"


runing the test will fail

TypeError: Cannot read properties of undefined (reading 'programId')

why and how to modify it works in local net ?

Create account fails

Looks like after commit e76ac6c, running the test for create account now fails.

My guess is, this is due to the hardcoding of Au21huMZuDQrbzu2Ec5ohpW5CKRqhcGV6qLawfydStGs as program ID in the test.

Below is the error:

  Create a system account
    1) Create the account


  0 passing (103ms)
  1 failing

  1) Create a system account
       Create the account:
     Error: failed to send transaction: Transaction simulation failed: Attempt to load a program that does not exist
      at Connection.sendEncodedTransaction (node_modules/@solana/web3.js/src/connection.ts:4934:13)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at Connection.sendRawTransaction (node_modules/@solana/web3.js/src/connection.ts:4893:20)
      at Connection.sendTransaction (node_modules/@solana/web3.js/src/connection.ts:4881:12)
      at sendAndConfirmTransaction (node_modules/@solana/web3.js/src/utils/send-and-confirm-transaction.ts:31:21)

Error: program file does not exist: ./target/deploy/counter_solana_native.so

I'm trying to run the yarn test from counter/native directory.

$ pwd
~/program-examples/basics/counter/native

$ yarn test
Error: program file does not exist: ./target/deploy/counter_solana_native.so
Error: server closed unexpectedly
    at ChildProcess.onClose (program-examples/basics/counter/native/node_modules/start-server-and-test/src/index.js:80:14)
    at ChildProcess.emit (node:events:390:28)
    at maybeClose (node:internal/child_process:1064:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
error Command failed with exit code 1.

I think yarn should detect which directory the test is invoked from. There should be a way to know the project root and that should be prefixed to the target/deploy/counter_solana_native.so path.

anchor test `basic/account-data` meet this problem

(node:28858) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
    1) Create the address info account
    2) Read the new account's data


  0 passing (81ms)
  2 failing

  1) Account Data!
       Create the address info account:
     Error: AnchorError caused by account: address_info. Error Code: AccountNotInitialized. Error Number: 3012. Error Message: The program expected this account to be already initialized.
      at Function.parse (node_modules/@project-serum/anchor/src/error.ts:167:14)
      at translateError (node_modules/@project-serum/anchor/src/error.ts:276:35)
      at MethodsBuilder.rpc [as _rpcFn] (node_modules/@project-serum/anchor/src/program/namespace/rpc.ts:35:29)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)

  2) Account Data!
       Read the new account's data:
     Error: Account does not exist ESowwGuph5bQso9ycdi7R7hKNvirUpYErzfU19ATdZhb
      at AccountClient.fetch (node_modules/@project-serum/anchor/src/program/namespace/account.ts:154:13)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)



error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

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.