Failed to deploy my Solana smart contract

Viewed 582
1 Answers

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 {}
Related