0

I have setup the Anchor.toml fiel for the devnet but got the error in the test cases some thing like "request to http://localhost:8899/ failed, reason: connect ECONNREFUSED 127.0.0.1:8899", Why anchor uses localnet, even I set the devnet to Anchor.toml file This is my anchor.toml file

[programs.devnet]
program = "BNhE6E4o3aA44wRoTvbPnrFfmpNrSnuUoWGgLzJ2Mds1"
[registry]
url = "https://anchor.projectserum.com"
[provider]
cluster = "devnet"
wallet = "/home/name/.config/solana/id.json"
[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 test.ts"

I already set to devnet Also I use anchor.AnchorProvider.env() while initializing in the test script

2
  • Can you please post your Anchor.toml?
    – sohrab
    Commented Jul 31, 2022 at 23:21
  • Maybe you edited Anchor.toml and forgot to Save ? Commented Aug 1, 2022 at 0:47

2 Answers 2

2

Make sure you set both programs and provider to devnet.

[programs.devnet]
your_program = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
[provider]
cluster = "devnet"

You can also set multiple program Ids for different networks, for example:

[programs.localnet]
your_program = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"

[programs.devnet]
your_program = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
1
  • I already set this but this does not work for me
    – Aslam
    Commented Aug 1, 2022 at 11:34
1

You likely should change your Solana cli configuration using Solana config set --url https://api.devnet.solana.com. If this doesn't solve the issue, confirm that your provider is set to anchor.AnchorProvider.env() in your testing code.

2
  • Already set like this
    – Aslam
    Commented Aug 1, 2022 at 11:34
  • Delete your target folder and rebuild
    – Ademola
    Commented Aug 1, 2022 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.