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

    // Initialize RWA metadata and mint
    pub fn initialize_rwa(
        ctx: Context<InitializeRwa>, 
        uri: String, 
        name: String, 
        total_supply: u64, 
        price_per_fraction: u64
    ) -> Result<()> {
        // Validate the URI and name lengths
        require!(uri.len() <= 200, RwaError::UriTooLong);
        require!(name.len() <= 50, RwaError::NameTooLong);

        // Set up the RWA metadata
        let rwa_metadata = &mut ctx.accounts.rwa_metadata;
        rwa_metadata.uri = uri;
        rwa_metadata.name = name;
        rwa_metadata.creator = *ctx.accounts.creator.key;
        rwa_metadata.total_supply = total_supply;
        rwa_metadata.price_per_fraction = price_per_fraction;
        rwa_metadata.current_holders = 0;
        rwa_metadata.mint = ctx.accounts.mint.key();

        Ok(())
    }

   
#[derive(Accounts)]
pub struct InitializeRwa<'info> {
    #[account(
        init, 
        payer = creator, 
        space = 8 + // discriminator
                32 + // creator (Pubkey)
                32 + // mint (Pubkey)
                8 + // total_supply (u64)
                8 + // price_per_fraction (u64)
                8 + // current_holders (u64)
                4 + 200 + // uri (String max 200 chars)
                4 + 50 // name (String max 50 chars)
    )]
    pub rwa_metadata: Account<'info, RWAMetadata>,
    #[account(mut)]
    pub creator: Signer<'info>,
    #[account(
        init,
        payer = creator,
        mint::decimals = 2,
        mint::authority = creator,
    )]
    pub mint: InterfaceAccount<'info, Mint>,
    pub system_program: Program<'info, System>,
    pub token_program: Program<'info, Token2022>,
    pub rent: Sysvar<'info, Rent>,
}



#[account]
pub struct RWAMetadata {
    pub uri: String, // Max 200 characters
    pub name: String, // Max 50 characters
    pub creator: Pubkey,
    pub mint: Pubkey,
    pub total_supply: u64,
    pub price_per_fraction: u64,
    pub current_holders: u64,
}

#[error_code]
pub enum RwaError {
    #[msg("The amount exceeds the total supply")]
    ExceedsTotalSupply,
    #[msg("Calculation error")]
    CalculationError,
    #[msg("URI is too long (max 200 characters)")]
    UriTooLong,
    #[msg("Name is too long (max 50 characters)")]
    NameTooLong,
}

1 Answer 1

0

unknown signer error might occur when you try to send your transaction with a non-signer address.

In your test cases, is the creator address similar to that of your anchor workspace?

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.