Secret Network
Secret Network Ecosystem
3 min readMay 16, 2024

--

Developer Tutorial: Secret Network/Linea Cross-Chain VRF

In this developer tutorial, you will learn how to request a verifiable random number on Linea from Secret Network by deploying your own Linea randomness contract. You will also learn how to use SecretPath as a cross-chain bridging solution for Linea, unlocking limitless cross-chain functionality.

See a fullstack cross-chain Linea VRF demo here

Linea Prerequisites

  1. Add Linea Sepolia testnet to your wallet (scroll to the bottom of the testnet explorer and click “Add Linea Sepolia Testnet Network”
  1. Fund your Linea Sepolia testnet wallet

Deploy RandomnessReceiver.sol

Once you have funded your Linea Sepolia testnet wallet, it is time to deploy your Linea testnet RandomnessReceiver.sol contract.

  1. Copy the RandomnessReceiver.sol contract
  2. Create a blank workspace on Remix
  3. Create a file called “RandomnessReceiver.sol” and paste the RandomnessReceiver contract
  4. Compile RandomnessReceiver.sol
  5. Navigate to the “Deploy & Run Transactions” tab and switch the environment to “injected provider — Metamask” (be sure your Metamask is toggled to Linea testnet, with chain id 59141). Toggle the Contract to “RandomnessReceiver.sol”:
  1. Then click deploy 🙂

Set Linea gateway contract address

Now that you have a deployed contract address on Linea, it is time to set the Linea testnet gateway contract address (this is the public address that bridges to Secret Network with SecretPath. The gateway address for Linea is ‘0x8EaAB5e8551781F3E8eb745E7fcc7DAeEFd27b1f’

And can be found in Secret’s docs here

Paste the contract address above and then call the “SetGatewayAddress” method:

Request randomness from RandomnessReceiver.sol

Now that you have successfully set your gateway address for Linea, it’s time to request verifiable randomness! To request randomness:

  1. Add gas to the contract call:
  1. Request randomness by calling requestRandomnessTestPreset. It is designed to request 20 random bytes:
function requestRandomnessTestPreset() external payable {

// Can be up to 2000 random numbers, change this according to your needs

uint32 numWords = 20;

// Change callbackGasLimit according to your needs for post processing in your callback

uint32 callbackGasLimit = 300000;

// Get the VRFGateway contract interface

ISecretVRF vrfContract = ISecretVRF(VRFGateway);

// Call the VRF contract to request random numbers.

// Returns requestId of the VRF request. A contract can track a VRF call that way.

uint256 requestId = vrfContract.requestRandomness{value: msg.value}(numWords, callbackGasLimit);

// Emit the event

emit requestedRandomness(requestId);
}

If you paid enough gas, your transaction hash will be returned! You can view your 20 random bytes by navigating to the Events tab:

And then your random bytes will be listed like so:

Summary + Secret Raffle

Congrats! You’ve successfully requested cross-chain randomness on Linea from Secret Network 🌟Please fill out the form here to be entered into the raffle for 50 SCRT.

--

--

Secret Network
Secret Network Ecosystem

The Data Privacy Platform For Web3 — build and use blockchain applications that are both permissionless and privacy-preserving.