🥞 A Python client for accessing PancakeSwap Lottery smart contract information through Web3.py
PancakeSwap Lottery 🥞 - Web3 client
A Python client for accessing PancakeSwap Lottery smart contract information through Web3.py.
Documentation: https://frefrik.github.io/pancakeswap-lottery
Examples: https://frefrik.github.io/pancakeswap-lottery/guide/examples
Source Code: https://github.com/frefrik/pancakeswap-lottery
PyPI: https://pypi.org/project/pancakeswap-lottery
Installation
Install from PyPI:pip install pancakeswap-lottery
Usage
from pancakeswap_lottery import LotteryV2
lottery = LotteryV2()
Current lottery round number
currentround = lottery.currentround()
Current ticket id
ticketid = lottery.current_ticket()
Status of lottery round
status = lottery.status()
Lottery draw date and time of lottery round
drawdate = lottery.drawdate()
Ticket price in CAKE
ticketprice = lottery.ticketprice()
Total prize pool of lottery round in CAKE
prizepool = lottery.prizepool()
Prize pool allocation in CAKE
allocation = lottery.prizepoolallocation()
Total number of tickets in lottery round
totaltickets = lottery.totaltickets(lotteryround=23)
Winning numbers for lottery round
winningnumbers = lottery.winningnumbers(lotteryround=16)
Get lottery winnings (CAKE) for a given address and round
addresswinnings = lottery.addresswinnings(address="0x621D6ee5FA9634d86396C13fAaD6A7827606A6d7", lotteryround=16)
Get lottery winnings (CAKE) for a given ticket and round
ticketwinnings = lottery.ticketwinnings(lotteryround=10, ticketid=158408)
Number of winners per prize bracket
winners = lottery.winnersperbracket(lotteryround=16)
Amount of CAKE won per ticket in each prize bracket
cakeperbracket = lottery.cakeperbracket(lotteryround=16)
Percentage probability of winning the lottery
winningprobability = lottery.winningprobability()
Data from historic lottery rounds can also be pulled
status = lottery.status(lotteryround=10)
drawdate = lottery.drawdate(lotteryround=10)
ticketprice = lottery.ticketprice(lotteryround=10)
prizepool = lottery.prizepool(lotteryround=10)
allocation = lottery.prizepoolallocation(lotteryround=10)
Response previews
>>> lottery.current_round()
20
>>> lottery.current_ticket() 1124981
>>> lottery.status() Open
>>> lottery.draw_date() 2021-07-12 20:00:00
>>> lottery.ticket_price() 0.32
>>> lottery.prize_pool() 63024
>>> lottery.prizepoolallocation() {'match1': 630, 'match2': 1891, 'match3': 3781, 'match4': 6302, 'match5': 12605, 'match6': 25210, 'burn': 12605}
>>> lottery.total_tickets(lotteryround=23) 14253
>>> lottery.ticket_winnings(lotteryround=15, ticketid=567093) 865.536634168
>>> lottery.address_winnings("0x621D6ee5FA9634d86396C13fAaD6A7827606A6d7", lotteryround=16) {'tickets': 8, 'ticketids': [634970, 634971, 634972, 634973, 634974, 634975, 634976, 634977], 'winning_tickets': [634970, 634971]}
>>> lottery.winning_numbers(lotteryround=16) 743350
>>> lottery.winnersperbracket(lotteryround=16) {'match1': 19133, 'match2': 1921, 'match3': 188, 'match4': 21, 'match5': 1, 'match6': 1}
>>> lottery.cakeperbracket(lotteryround=16) {'match1': 0, 'match2': 3, 'match3': 62, 'match4': 925, 'match5': 38843, 'match6': 77687}
>>> lottery.winning_probability() {'match1': 10.0, 'match2': 1.0, 'match3': 0.1, 'match4': 0.01, 'match5': 0.001, 'match6': 0.0001}
Lottery V1
Usage (Lottery V1)
from pancakeswap_lottery import Lottery
lottery = Lottery()
Current lottery round
issueindex = lottery.getissue_index()
Total pot (CAKE) of current lottery round
totalamount = lottery.gettotal_amount()
Prize pool allocation (percent)
allocation = lottery.get_allocation()
Total addresses
totaladdresses = lottery.gettotal_addresses()
Drawed
drawed = lottery.get_drawed()
Drawing phase
drawingphase = lottery.getdrawing_phase()
Last timestamp
timestamp = lottery.getlasttimestamp(epoch=False)
Date and time of lottery round
lotterydate = lottery.getlottery_date(432)
Total rewards of lottery round
totalrewards = lottery.gettotal_rewards(432)
Winning numbers of lottery round
historynumbers = lottery.gethistory_numbers(432)
Numbers of tickets matched
historyamount = lottery.gethistory_amount(432)
Numers of tickets matched a specified number
matchingrewardamount = lottery.getmatchingreward_amount(432, 3)
Lottery numbers for a given ticket
lotterynumbers = lottery.getlottery_numbers(1328060)
Rewards for a given ticket
rewardview = lottery.getreward_view(1328060)
Max number
maxnumber = lottery.getmax_number()
CAKE contract address
cakecontract = lottery.getcake()
PLT-token contract address
lotterycontract = lottery.getlotteryNFT()
Total number of tickets bought by a given address
balance = lottery.getbalanceof("0xc13456A34305e9265E907F70f76B1BA6E2055c8B")
Response previews (Lottery V1)
>>> lottery.getissueindex()
435
>>> lottery.gettotalamount() 34977.25
>>> lottery.get_allocation() {'1': 50, '2': 20, '3': 10}
>>> lottery.gettotaladdresses() 200
>>> lottery.get_drawed() False
>>> lottery.getdrawingphase() False
>>> lottery.getlasttimestamp(epoch=False) 2021-03-27 11:38:49
>>> lottery.getlotterydate(432) 2021-03-26 02:00:00+00:00
>>> lottery.gettotalrewards(432) 51384.125
>>> lottery.gethistorynumbers(432) [2, 13, 7, 3]
>>> lottery.gethistoryamount(432) {'4': 1, '3': 34, '2': 718}
>>> lottery.getmatchingreward_amount(432, 3) 34
>>> lottery.getlotterynumbers(1328060) [11, 5, 14, 6]
>>> lottery.getrewardview(1328060) 0
>>> lottery.getmaxnumber() 14
>>> lottery.getminprice() 1
>>> lottery.get_cake() 0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82
>>> lottery.get_lotteryNFT() 0x5e74094Cd416f55179DBd0E45b1a8ED030e396A1
>>> lottery.getbalanceof("0xc13456A34305e9265E907F70f76B1BA6E2055c8B") 2673
Donate
If you found this library useful and want to support my work feel free to donate a small amount 🙏🏻- 🥞 CAKE: 0xCFad66049e2C9Bc28647B2e2e3449B6B7C602d42
- Ξ ETH: 0x7E916c46157f012Fb8dece4A042Dc603e8d627Df
- ₿ BTC: bc1qgn2mdf5wsxft33s3ea8sh060y85mzntzs8cuu7
License
This project is licensed under the terms of the MIT license.
Disclaimer
This project is not affiliated with the PancakeSwap team.