Quantcast
Channel: How can a Solana Rust smart contract get block height or Unix time? - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 5

Answer by Yilmaz for How can a Solana Rust smart contract get block height or Unix time?

$
0
0
// pass this to Context#[derive(Accounts)]pub struct CreatePost<'info> {    // add other properties    pub post: Account<'info, PostAccount>,    // Clock to save time of post    pub clock: Sysvar<'info, Clock>,}

PostAccount struct:

#[account]pub struct PostAccount {    // add other properties    // post time    pub post_time: i64,}

Define function in mod

pub fn create_post(ctx: Context<CreatePost>) -> ProgramResult {     let post = &mut ctx.accounts.post;     // get the timestamp of post     post.post_time = ctx.accounts.clock.unix_timestamp; }   

Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>