project-serum / serum-ts

Project Serum TypeScript monorepo
https://projectserum.com
Apache License 2.0
272 stars 246 forks source link

Serum making localhost requests, while solana config is set to devnet #179

Closed rav3nh0lm closed 3 years ago

rav3nh0lm commented 3 years ago

I am using anchor 0.16.2, and following typescript packages

"@project-serum/anchor": "^0.16.2",
"@solana/spl-token": "^0.1.8",
"dotenv": "^10.0.0",
  "yargs": "^16.2.0"

I set my solana config to the following variables

$ solana config get
Config File: /Users/raven/.config/solana/cli/config.yml
RPC URL: https://api.devnet.solana.com 
WebSocket URL: wss://api.devnet.solana.com/ (computed)
Keypair Path: /Users/raven/.config/solana/id.json 
Commitment: confirmed 

and am invoking the following code

ANCHOR_PROVIDER_URL="https://api.devnet.solana.com" ANCHOR_WALLET=/Users/raven/.config/solana/id.json npm run serve 

to run an expressJS server (typescript).

whenever I make an API call through the following code

    const provider = anchor.getProvider()
    const poolSigner = _poolSigner;
    const currentBid = await getTokenAccount(provider, userRedeemable)
    await exchangeUsdcForRedeemableRpc(
        poolAccount,
        poolSigner,
        provider.wallet.publicKey,
        userUsdc,
        account.redeemableMint,
        userRedeemable,
        account.poolUsdc,
        depositAmount,
    ); 

I get an error

Error making the bidding request!
{}
Error: failed to get info about account AfQRhis7aZg6NmPpjrFN1KpZviMEp6H1VnKBzHkBxckK: FetchError: request to http://localhost:8899/ failed, reason: connect ECONNREFUSED 127.0.0.1:8899
    at Connection.getAccountInfo (/Users/raven/imo-launchpad/example-server/node_modules/@solana/web3.js/src/connection.ts:2443:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async AccountClient.fetchNullable (/Users/raven/imo-launchpad/example-server/node_modules/@project-serum/anchor/src/program/namespace/account.ts:128:25)
    at async AccountClient.fetch (/Users/raven/imo-launchpad/example-server/node_modules/@project-serum/anchor/src/program/namespace/account.ts:152:18)

In short: The request is made to the local testnet, instead of to devnet / the development cluster. I find this weird, as in all instances that I could do, I have made sure to set the Solana cluster to https://api.devnet.solana.com.

When I control-F the entire project, I only see the following code-snippet to include localhost:8899 as the link

static local(url?: string, opts?: ConfirmOptions): Provider {
    opts = opts ?? Provider.defaultOptions();
    const connection = new Connection(
      url ?? "http://localhost:8899",
      opts.preflightCommitment
    );
    const wallet = NodeWallet.local();
    return new Provider(connection, wallet, opts);
  }

manualy changing this in the node_modules did not resolve this, however.

Is there anything wrong that I do, or anything I'm missing? The request is made to the local testnet, instead of to devnet / the development cluster. Any help would be greatly appreciated, this is the last bug that stands between me and devnet. This is for the ignition hackathon in 2 days, so I would appreciate any help a lot! :)

rav3nh0lm commented 3 years ago

Upon further debugging, it's actually the line const account = await program.account.poolAccount.fetch(poolAccount); that makes the request to localhost, instead of the devnet.

My Anchor.toml looks as follows

[programs.devnet]
imo_launchpad = "5bcVGSYUFA2AKvweh3V5mg9zGjweioQQVvk18UCYjTR1"
cluster = "https://api.devnet.solana.com"

#[programs.localnet]
#imo_launchpad = "5bcVGSYUFA2AKvweh3V5mg9zGjweioQQVvk18UCYjTR1"

[registry]
url = "https://anchor.projectserum.com"

[provider]
cluster = "https://api.devnet.solana.com"
url = "https://api.devnet.solana.com"
wallet = "/Users/raven/.config/solana/id.json"

[scripts]
test = "/usr/local/bin/node /usr/local/bin/mocha -t 1000000 --require ts-node/register tests/imo-launchpad.ts"
armaniferrante commented 3 years ago

Please move this to the Anchor repository. https://github.com/project-serum/anchor

rav3nh0lm commented 3 years ago

Apologies and done: https://github.com/project-serum/anchor/issues/880 ! Thanks for the swift response @armaniferrante :)