user1849313
user1849313

Reputation: 103

Failed to deploy my Solana smart contract

I tried to deploy my Solana smart contract, but I encountered the following error: "Error: Deploying program failed: Error processing Instruction 1: invalid account data for instruction"

May I have your help to take a look at this failed deployment https://solscan.io/tx/c8VBq8sE5XP2Q75pvLXsyGhehC3Utj1zS9fatunHuvgVDdGobKhupvFUXBTb7DxPfeneSskmEZhszrdPqpXSsyg?cluster=devnet?

Thanks!

Upvotes: 2

Views: 1640

Answers (1)

Jon C
Jon C

Reputation: 8472

This one is subtle, but the error is contained in the logs of your transaction if you look at the "Raw" Program Logs.

It says: ELF error: Found writable section (.bss._ZN5ahash12random_state11RAND_SOURCE17h85a33855e0b029fbE) in ELF, read-write data not supported

Solana programs can't have writable static data, and if your program has a bss section, it means there is some writable static data. It could be from a Hasher or randomizer. More info at https://docs.solana.com/developing/on-chain-programs/overview#static-writable-data

If you need a form of mapping, use BTreeMap which is currently supported. Here is a small example Anchor program:

use anchor_lang::prelude::*;
use std::collections::BTreeMap;
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
#[program]
mod basic_0 {
    use super::*;
    pub fn initialize(_ctx: Context<Initialize>) -> ProgramResult {
        let mut map = BTreeMap::new();
        map.insert("key1", "value1");
        map.insert("key2", "value2");
        Ok(())
    }
}
#[derive(Accounts)]
pub struct Initialize {}

Upvotes: 0

Related Questions