> For the complete documentation index, see [llms.txt](https://docs.luckblocks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.luckblocks.com/auto-spin-draw/how-queue-works.md).

# How queue works

Explanation on how NFTNode execution queue works

Each lottery will have a timer, specifically 24 hours interval for daily draw and 7 days interval for weekly draw, nodes will be checking this trough the autospin function which run successfully if its on correct time using current timestamp vs last autospin execution timestamp and if there’s x number of players and y amount in USD in the jackpot (converted by the crypto price) , the function will be executed by these users/nodes via their own script on their servers or via “**gelato**” servers which is a decentralized network of PCs running functions automatically as a service for end users. In order to receive rewards, you have to first stake the NFT from **Luckblocks** **NFTnodes** collection on our platform, this step is needed for the configuration smartcontract to guarantee your ownership, set your NFT on the on-chain queue system and take it out from the market, as you couldn’t sell a activated **NFTnode.**\
\
The payments will be rotative and random for the active nodes , so we will have a <mark style="background-color:green;">active queue</mark> (nfts that hasn’t paid yet) and a <mark style="background-color:yellow;">waiting queue</mark> (nfts that is recently configured or already paid on that round).

### Lets take this process of staking and round of payment as example:

**Bob** has staked his NFTs of ID 20 and 34, the contract will config those tokens as Bob Tokens.

and **Alice** has staked her NFT of ID 11, the contract will config those tokens as Alice Token.

so now they configure the automation to run the function autospin() with this IDs and their wallet, all the 4 lotteries has this function and with same NFT you can run the autospin function on any and all of them, when the function is executed, the **Luckblocks** contract will activate those nodes to receive rewards on next round, puting them on the <mark style="background-color:yellow;">waiting queue</mark>.

**Luckblocks** contract do a check if there’s any tokens yet to receive reward on the <mark style="background-color:green;">active queue</mark>, if there’s none, it pays a random waiting node execute the draw function and put all tokens from the <mark style="background-color:yellow;">waiting queue</mark> to the <mark style="background-color:green;">active queue</mark>.

in that example we have \[20,34,11] <mark style="background-color:yellow;">waiting queue</mark> and no <mark style="background-color:green;">active queue</mark>.

lets say it paid **34**, so Bob receives reward in <mark style="color:green;">**USDT**</mark> and contract put all these tokens to the <mark style="background-color:green;">active queue.</mark>

then the cycle repeats, on next autospin it chooses a random active node, since we now have tokens there, lets say it now it chose NFT number **20**, it will pay Bob reward in <mark style="color:green;">**USDT**</mark> and put that paid token to the waiting queue.

The <mark style="background-color:green;">active queue</mark> now looks like this **\[34,11]**. and <mark style="background-color:yellow;">waiting queue</mark> like this **\[20]**.

Each lottery/game smartcontract has its own queue, so if token **20** executed the <mark style="color:orange;">**BTC**</mark> auto spin, it will be able to run for <mark style="background-color:purple;">**CRA**</mark><mark style="color:red;background-color:purple;">**N**</mark><mark style="color:green;background-color:purple;">**N**</mark><mark style="background-color:purple;">**I**</mark> ,<mark style="color:blue;">**ETH**</mark> or <mark style="color:purple;">**POL**</mark> lotteries, if on the active queue for these lotteries.

If there’s NFTs on the <mark style="background-color:green;">active queue</mark> where the owners is not executing the autospin function,after 5 minutes the contract will auto resets queue and slash these nft tokens from the list , so the queue doens’t hang up, and so that the active nodes which were on the <mark style="background-color:yellow;">waiting queue</mark> can back up to the <mark style="background-color:green;">active queue</mark> and run the function normally.
