Quantcast
Viewing all articles
Browse latest Browse all 5

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

Is this what you mean when you say "smart contract itself to get the current time"?

#[program]mod hello_anchor {    use super::*;    pub fn initialize(ctx: Context<Initialize>) -> Result<()> {        let clock = Clock::get().unwrap();        msg!("Timestamp: {}!", clock.unix_timestamp); // Message will show up in the tx logs        Ok(())    }}#[derive(Accounts)]pub struct Initialize {}

The program log will look like this

Image may be NSFW.
Clik here to view.
enter image description here


Viewing all articles
Browse latest Browse all 5

Trending Articles



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