BridgeLottery is an open-source project that allows bridge owners to implement a lottery in just a few minutes.
Firstly, the Bridgelottery script listens for transactions on the bridge defined in the config.json file as the eventAddress for the time defined in the subscriptionDurationInSeconds variable. A smart contract called depositor.sol is deployed in parallel and each address of users who have used the bridge are mapped inside.
When subscriptionDurationInSeconds is over, the script then call the smart contract called randomNumber.sol using Chainlink to obtain a random number and selects the winner using this formula: randomNumberGeneratedFromChainlink % numberOfParticipants. => The winner is then the address in the array corresponding to the result.
Finally, in the following example, the winner receives an attestation from EAS certifying that he has won the lottery, with a timestamp indicating the date of the win. As the prize for the lottery, the winner also receives an NFT on Zora Goerli chain.
We have built this project by doing a nodejs script that listen txs on the bridge, 2 smart contracts, one for the mapping of each participant and the other to get a random number from Chainlink. We also deployed 2 live examples by clonning the frontend of Optimism Bridge and Mode Bridge.
Sponsors that we are using :