5

I'm trying to get the slot number at runtime. In evm we can just call block.number to get current block number, i need something equivalent to block.number.

I tried SlotHistory::get() but it throws an error in test environment when using anchor test. I also tried to give it as account in context but it threw another error saying sysvar address mismatch.

I guess something is wrong with test environment.


Edit

I found the error message Unsupported sysvar

2 Answers 2

5

Through the clock sysvar

use solana_sdk::clock::Clock;

let slot = Clock::get()?.slot;
0

Use Clock instead of SlotHistory

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.