I'm building a program to co-sign transaction on solana.
The sign mechanism works, but now I'm trying to extract the account data length from a transaction that I'm receiving, because I want to calculate the cost of creating the account.
I'm sending this transaction from the frontend to the backend to co-sign it:
await program.value.transaction.sendTweet(topic, content, {
accounts: {
author: wallet.value.publicKey,
feePayer: company_account_pubkey,
tweet: tweet.publicKey,
systemProgram: web3.SystemProgram.programId,
}
});
The contract is:
#[derive(Accounts)]
pub struct SendTweet<'info> {
#[account(init, payer = feePayer, space = 1372)]
pub tweet: Account<'info, Tweet>,
#[account(mut)]
pub author: Signer<'info>,
#[account(mut)]
pub feePayer: Signer<'info>,
#[account(address = system_program::ID)]
pub system_program: AccountInfo<'info>,
}
#[account]
pub struct Tweet {
pub author: Pubkey,
pub timestamp: i64,
pub topic: String,
pub content: String,
}
So just looking at the contract I can understand that the space required will be 1372.
But my service will interact with a lot of other programs, so I want to be able to extract the account data length by the transaction that I'm receiving.
On solana py, I know that I can get the data with tx.instructions[0].data
and I know that I can get the cost of rent with client.get_minimum_balance_for_rent_exemption(1372)
But I don't know how to extract the size of the account from the transaction itself.
What am I missing?
I don't think the size of the account is included in the transaction info. It might be buried in
getTransaction
return values somewhere, but most likely you have to make a getAccountInfo call which will include the data, and you can check the length ofdata
returned by it.