1

I'm trying to deploy my Solana program to mainnet using anchor deploy --provider.cluster mainnet. When I first ran this command I got an insufficient funds error and it told me that I needed around 1.6 SOL in the program account. Just to be safe I sent 1.9 SOL to the pubkey that was output when it gave me the error. After I funded the account I tried deploying again with the same command and I got the error: Deploying program failed: Error processing Instruction 1: custom program error: 0x1. Then I tried to recover my funds so that I could deploy again. I recovered the keypair and then I tried running the same command again.

This time I got this in the console:

Deploying workspace: https://api.mainnet-beta.solana.com
Upgrade authority: /Users/dylanmolina/.config/solana/id.json
Error: expected !

I know that this error usually means that there's some sort of syntax error in the command but I believe that it's correct: anchor deploy --provider.cluster mainnet

Is there something else that may be causing this? Should I have more SOL in my program balance(currently at ~3.99 SOL)? Is this a syntax error? Faulty program? Any help would be appreciated here, thanks!

For reference:

anchor.toml:

[features]
seeds = false
skip-lint = false
[programs.devnet]
artsolbackend = "8oMdunAFJKYeLDwHa2KrhyNGvbLqk4uB3iC6g4nifuCm"

[registry]
url = "https://api.apr.dev"

[provider]
cluster = "devnet"
wallet = "/Users/dylanmolina/.config/solana/id.json"

[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"

lib.rs:

use anchor_lang::prelude::*;
use anchor_lang::solana_program::entrypoint::ProgramResult; //ProgramResult

declare_id!("8oMdunAFJKYeLDwHa2KrhyNGvbLqk4uB3iC6g4nifuCm");

#[program]
pub mod artsolbackend {
    use super::*;

    pub fn submit_post(ctx: Context<SubmitPost>, title: String, description: String, artwork: String, cta: String) -> Result<()> {
        let post: &mut Account<Post> = &mut ctx.accounts.post;
        let creator: &Signer = &ctx.accounts.creator;

        if title.chars().count() > 50 {
            return Err(error!(ErrorCode::TitleTooLong));
        }

        if description.chars().count() > 280 {
            return Err(error!(ErrorCode::DescriptionTooLong));
        }

        if cta.chars().count() > 150 {
            return Err(error!(ErrorCode::CTATooLong));
        }

        post.creator = *creator.key;
        post.title = title;
        post.description = description;
        post.artwork = artwork;
        post.cta = cta;

        Ok(())
    }
    pub fn send_sol(ctx: Context<SendSol>, amount: u64) -> ProgramResult {
        let ix = anchor_lang::solana_program::system_instruction::transfer(
            &ctx.accounts.from.key(),
            &ctx.accounts.to.key(),
            amount,
        );
        anchor_lang::solana_program::program::invoke(
            &ix,
            &[
                ctx.accounts.from.to_account_info(),
                ctx.accounts.to.to_account_info(),
            ],
        )
    }
}

#[derive(Accounts)]
pub struct SendSol<'info> {
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    from: Signer<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    to: AccountInfo<'info>,
    /// CHECK: This is not dangerous because we don't read or write from this account
    system_program: Program<'info, System>,
}

#[derive(Accounts)]
pub struct SubmitPost<'info> {
    #[account(init, payer = creator, space = Post::LEN)]
    pub post: Account<'info, Post>,
    #[account(mut)]
    pub creator: Signer<'info>,
    pub system_program: Program<'info, System>,
}

#[account]
pub struct Post {
    pub creator: Pubkey,
    pub title: String,
    pub description: String,
    pub artwork: String,
    pub points: i64,
    pub stars: u64,
    pub cta: String,
}

//Discriminator 
const DISCRIMINATOR_LENGTH: usize = 8;

//PubKey
const PUBLIC_KEY_LENGTH: usize = 32;

//String Prefix
const STRING_LENGTH_PREFIX: usize = 4;

//Title
const MAX_TITLE_LENGTH: usize = 50 * 4;

//Description
const MAX_DESCRIPTION_LENGTH: usize = 280 * 4;

//Artwork
const MAX_ARTWORK_LENGTH: usize = 100 * 4;

//Points & Stars
const INT_SIZE: usize = 8;

//CTA
const MAX_CTA_LENGTH: usize = 150 * 4;

impl Post {
    const LEN: usize = DISCRIMINATOR_LENGTH 
    + PUBLIC_KEY_LENGTH  //Creator
    + STRING_LENGTH_PREFIX + MAX_TITLE_LENGTH //Title
    + STRING_LENGTH_PREFIX + MAX_DESCRIPTION_LENGTH //Description
    + STRING_LENGTH_PREFIX + MAX_ARTWORK_LENGTH //Artwork link
    + INT_SIZE //Points
    + INT_SIZE //Stars
    + STRING_LENGTH_PREFIX + MAX_CTA_LENGTH; //CTA
}

#[error_code]
pub enum ErrorCode {
    #[msg("The provided title should be 50 characters maximum!")]
    TitleTooLong,

    #[msg("The provided description should be 280 characters maximum!")]
    DescriptionTooLong,

    #[msg("The provided artwork file should have a link that's 100 characters maximum!")]
    ArtworkTooLong,

    #[msg("The provided CTA link shouls be a maximum of 150 characters!")]
    CTATooLong,
}

1 Answer 1

1

Trying to make some informed guesses here.

You have cluster = "devnet" in your Anchor.toml. I recommend setting it to mainnet while deploying to mainnet.

I also recommend setting the cluster to mainnet in the command line, as in solana config set -u m.

That will then save you the --provider.cluster mainnet, and you can just issue a plain anchor deploy.

The funds will be deducted from the wallet that's set as update authority, in your case /Users/dylanmolina/.config/solana/id.json. No need to transfer anything.

In my case it was 8 SOL, so be sure to have enough funds in your wallet.

When you later close the account (i.e. un-deploy your program), you will get your deposit back.

2
  • Thanks for the answer it really moved me forward. Now I'm using solana program deploy instead of anchor deploy because I need to recover the funds to continue the deployment. However, after passing in all the args and using the correct flags(it seems), I'm getting this error: Initial deployments require a keypair be provided for the program id. Right now I'm just passing in the program id that I declared in lib.rs after the --program-id flag but I'm not sure if I need to use the entire keypair or how to even get it. Commented Aug 17, 2022 at 0:39
  • 2
    please post a new question instead of starting an unrelated conversation in the comments
    – trent.sol
    Commented Aug 17, 2022 at 1:52

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.