1

I'm writing a game for the solana blockchain, and my plan is to store asset attributes as account data ( ~100 byte ) that can be mutable, and then reference the data in this account from a token metadata.

My understanding is that i have to create an account from the client side, with data size big enough for storing this data, using the public key from newely generated web3 keypair, but then how to store the private key in a wallet ?

This private key is what is going to be used to modify the data in the account ?

So how is it possible to create a data account with persistant mutable data associated with a phantom wallet address, and then use this address to later mutate the account data with a phantom wallet action ?

I understand the mainstream way to do this is using metaplex, and storing the metadata off chain, but then it's either using immutable storage and "fake mutability" by creating a modified copy and the previous version stay hanging there uselessly, or store the data on my server, but then modification are made by the backend, and i'd rather have the mutate action executed by the blockchain directly in the same transation than the action. ( it's not very mutation intensive either), to avoid hack or suspicion on this metadata state.

1

1 Answer 1

2

Can you make the data account a PDA, and add a field that contains the phantom wallet address? You can then only allow the signer to be this phantom wallet and using an anchor constraint make sure the address matches the one in the data account field.

#[account]
pub struct DataAccount {
   phantom_pub_key: Pubkey 
   // other fields ...

} 

#[derive(Account)] 
pub struct Initialize<'info> {
    /// CHECK: not dangerous
    #[account(mut, signer, constraint=data_account.phantom_pub_key == pubkey!("YOUR PUBLIC PHANTOM ADDRESS"))]
    pub initializer: AccountInfo<'info>,
    #[account(mut)] 
    pub data_account: Account<'info, DataAccount>,
}

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.