I can not deploy the program to dev net with anchor
Asked Answered
P

4

11

I get this error where I run anchor deploy:

Deploying workspace: http://127.0.0.1:8899
Upgrade authority: /home/<user>/.config/solana/id.json
Deploying program "faucet"...
Program path: /home/<user>/Workspace/<project_path>/target/deploy/xxx.so...
Error: RPC request error: cluster version query failed: error sending request for url (http://127.0.0.1:8899/): error trying to connect: tcp connect error: Connection refused (os error 111)
There was a problem deploying: Output { status: ExitStatus(ExitStatus(256)), stdout: "", stderr: "" }.

Before deploying, I have already run the following to change the cluster config in local:

solana config set --url https://api.devnet.solana.com

How can I solve the problem?

Parrett answered 19/8, 2021 at 14:0 Comment(1)
Today I got the same error while trying to deploy to devnet, turns out this is simply because the devnet is down. If you have been trying to deploy with no luck, you can check if the network is up and running: status.solana.com You can see for example that Solana's devnet is suffering from a major outage on the day of writing this answer, keep that possibility in mind even though it is a rarity.Alpers
G
19

Your error clearly states that while you are trying to deploy to your local network, it is not up and running. So, what you have to do is simply open a new terminal window and run:

solana-keygen new

save the seed phrase and other relevant details somewhere secure and then, run

solana-test-validator

Now in a separate terminal window where you had earlier tried to deploy, type

anchor deploy 

again and it should be successfully deployed.

Else, if you were trying to deploy on any other network, for example, devnet. Then you would want to airdrop some SOL into the account generated after running solana-keygen new using the command:

solana airdrop 1 <RECIPIENT_ACCOUNT_ADDRESS> --url https://api.devnet.solana.com

Then use additional flags in your deploy command as follows:

anchor deploy --provider.cluster devnet
Good answered 17/10, 2021 at 10:34 Comment(0)
G
12

Your error suggests that you are actually trying to deploy to local but your local is down. When deploying to clusters other than local, you need to add

anchor deploy --provider.cluster devnet

you can get more help from

anchor --help
Goldarned answered 19/8, 2021 at 15:58 Comment(3)
The problem before is solved by your way. But got another error. Error: Account HQwsYucNoomXvp6zwYUAwwxkSbewi2uKt95KsLJqt25Q has insufficient funds for spend (1.32421656 SOL) + fee (0.004175 SOL) I found that there is no this account under my project folder, which is weired because there is the account in my local.Parrett
Sorry, not enough funds for that account. Can deploy nowParrett
how did you resolve the balance problem? I'm airdropping SOL faucets, but still getting the insufficient funds error.Flown
P
5
  • solana config set --url devnet

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

  • this is how anchor will know where to deploy solana program to. we need to air drop

    solana airdrop 2 --url devnet

    solana balance --url devnet


{

If you want to create a wallet specific to each project

in andhor.toml file

 wallet = "./id.json"

then in the project directory:

 solana-keygen new -o id.json  

this will generate this:

 pubkey: 9bFcXvyjBuELw522FTRSU1umTTGaSLLD5iujjpQK6wt6

since you are using this wallet airdro

 solana airdrop 2 9bFcXvyjBuELw522FTRSU1umTTGaSLLD5iujjpQK6wt6 --url devnet

}

  • open anchor.toml file. update the file

    // [programs.localnet] change to devnet
    [programs.devnet]
    
    // cluster = "localnet" change to devnet
    cluster = "devnet"
    
  • anchor build

this creates a new build with new programId. access this program id

  • solana address -k target/deploy/yourprojectname-keypair.json

this will give you the programId of deployed contract

  • Now in lib.rs and anchor.toml update the declareId with this code.

lib.rs

 declare_id!("paste the programId of deployed contract"); 

anchor.toml

  yourProjectName = "paste the programId of deployed contract"
  • now run anchor build again now we are ready to deploy

  • anchor deploy

Peen answered 29/4, 2022 at 21:2 Comment(0)
P
2

I face this same issue too. Think this will help you. https://medium.com/@lianxiongdi/solana-development-1-basic-operation-of-solana-cli-dcf156137e6

But let me summarize it.

  1. solana-keygen new --outfile solana/my_wallet.json (this will create a file called solana, inside will have your new key my_wallet.json)
  2. solana-keygen pubkey solana/my_wallet.json (check your wallet public key, you can skip the verify part and use my method)
  3. solana config get (to get your details)
  4. solana config set --keypair solana/my_wallet.json (set your keypair to the newly created wallet)
  5. solana config set --url https://api.devnet.solana.com (set it to devnet)
  6. solana airdrop 2 (airdrop to your wallet)
  7. solana balance (Ec2x4xwfxgLxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx) (use the public key you obtain in method 2, if it shows 2 then means your config file is correct and the 2 sol airdrop is into correct wallet.)
  8. anchor build
  9. solana address -k target/deploy/yourprojectname-keypair.json (get the programId)
  10. declare_id!("paste the programId of deployed contract") (put the programId into lib.rs contract)
  11. [programs.devnet] program_name = "FYp6ubFr3Jxxxxxxxxxxxxxxxxxxxxxxxx" (paste the programId to your Anchor.toml file)
  12. anchor build
  13. remember to check your: [provider] cluster = "devnet" wallet = "./tests/test-key.json"
  14. anchor deploy --provider.cluster devnet

Deploy successfully.

Prompter answered 27/9, 2022 at 4:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.