Native Solana program (no Anchor) that uses MagicBlock Ephemeral VRF via ephemeral-vrf-sdk: the user requests randomness; the VRF program callbacks with 32 bytes; you derive a value (e.g. 1–10) and store it in PlayerState.
Program id: ELajHfg4BFcoKrC7ARDKMmqoKQrZMbr88h3xAjy9PY4X (see src/lib.rs).
- Caller: user (signs as authority).
- Effect: creates the player PDA for seeds
["player", authority], writesPlayerState(discriminator,random_valueinitially0, bump). - File:
src/instructions/initialize_player.rs
- Caller: user (payer signs).
- Effect: checks queue / accounts, builds
RequestRandomnessParamsand CPIs the ephemeral VRF program withcreate_request_randomness_ix. Your program signs the CPI using the identity PDA (["identity"]under this program). The request encodes which callback to run and which accounts the VRF will pass when it invokes you (e.g. the player PDA as writable). This instruction does not set the final roll; it only records the request on-chain and triggers the VRF. - File:
src/instructions/request_randomness.rs
- Caller: the VRF program, not the user. Instruction data = fixed 8-byte prefix (see
vrf_lite::CALLBACK_CONSUME_RANDOMNESS) + 32 random bytes (40 bytes total).src/processor.rsroutes this beforeVrfInstruction::try_from_slice, because it is not the same layout as your wallet Borsh instructions. - Effect: verifies
VRF_PROGRAM_IDENTITYis the signer, parses the 32-byte seed, maps it (e.g.rnd::random_u8_with_range→ 1–10), updatesPlayerState.random_valueon the player PDA. - Files:
src/vrf_lite.rs,src/instructions/callback_consume_randomness.rs
cargo build-sbf
solana program deploy target/deploy/<your_program>.so --program-id reflex_program-keypair.jsonUpgrade the same program id when you change the .so (redeploy with the same program keypair).
cd test
npm install
# Off-chain Borsh checks only
npm test
# On-chain: devnet (or set SOLANA_RPC_URL / SOLANA_WS_URL); needs payer keypair
RUN_INTEGRATION=1 npm testRUN_INIT_INTEGRATION=1: also runs theinitialize_playerchain test (default off so you can focus on VRF if the player PDA already exists).AUTO_INIT_PLAYER=1: withRUN_INTEGRATION=1, creates the player PDA if missing before the VRF test.
PROGRAM_ID in the client matches getTestProgramId() in test/utils.ts (override with env).
Do not commit reflex_program-keypair.json or .env; they are listed in .gitignore.