Repository
https://github.com/nnmix/py-magicdice-bot
What Will I Learn?
- You will learn to automate a @magicdice Bot given your own rules
- You will learn to use Steem - Python Lib
- You will learn to program your own 'Rule Based' dice rolls
Requirements
Personal Prerequisite
- Existing STEEM Account

System prerequisites:
- Jupyter notebook for python
Knowledge prerequisites:
- Basic understanding of python programming
Difficulty
- Intermediate
Description
In this tutorial you will get the ability to automate your own flavored Dice Roller Bot for @magicdice on STEEM
Content
Before getting to the python scripting section you will need a STEEM account token to be used.
1. STEEM Account - Private Active Keys
2. Jupyter / Python
You can access Jupyter Online or Intall it locally on your PC
When done open a new python file:

When the file is open, if you are on the online version, you can delete existing sample cell by clicking the cell border (blue highlight) than double pressing 'D'

Until you have an empty cell to write your script within:

Now your jupyter editor is up you can start typing your code and run it by pressing ctrl+enter
3. Magic Dice Roller/ Python
Let us start talking about the magicdice roller implementation
- Using Python Steem Lib (pip install steem)
- First Doing The Dice Roll by sending a transaction with Memo inside containing
- the bet STEEM amount
- the target with 'under' or 'over'
- the client rand seed which is a sha256 of a random of length 10


- Then Wait For An Incoming Transaction Result From Magic Dice:

# Magic Dice Roll Script Sample
# Replace <private active keys by yours>
from steem import Steem
import hashlib, binascii, random, time
def randhash():
m = hashlib.sha256()
m.update((str(random.randint(1,101)*time.time())).encode('utf-8'))
m.update((m.hexdigest() + str(random.randint(1,101))).encode('utf-8'))
x = m.hexdigest()
return x[2:12]
def newTx(s, amount, direction, target):
randh = randhash()
query = "{0} {1} {2}".format(direction, target, randh)
s.commit.transfer('magicdice',amount,'STEEM', memo = query, account="aro.steem")
return randh
def roll(steem, amt) :
randh = newTx(steem, amt, 'under', 30)
txId = '-1'
won = 0
randh = str(randh)
# wait for the tx id
while True :
dta = steem.get_account_history('aro.steem', index_from=-1, limit=20)
for i in range(len(dta)):
dd = dta[i][1]
if dd['op'][0] == 'transfer' and dd['op'][1]['to'] == 'magicdice' and dd['op'][1]['memo'].find(randh) > -1:
txId = str(dd['trx_id'])
break
if str(txId) != '-1':
break
time.sleep(2)
# wait for the result
while True :
dta = steem.get_account_history('aro.steem', index_from=-1, limit=20)
for i in range(len(dta)):
dd = dta[i][1]
if dd['op'][0] == 'transfer' and dd['op'][1]['from'] == 'magicdice' and dd['op'][1]['memo'].find(txId) > -1:
if dd['op'][1]['amount'] == '0.001 STEEM':
won = -1
else:
won = 1
break
if won != 0:
break
time.sleep(2)
return txId, won, randh
s = Steem(keys=["<private active keys>", "<private active keys>"])
st = time.time()
# do one dice roll
txId, won, randh = roll(s, 0.1)
et = time.time()
# show results: wait time, transaction Id, win as 1 and lost as -1
print(et - st, txId, won)
The End!
Finally most of the steps are covered, it is your time to configure your own rules / algorithm that may give you your optimal winning payouts.
Feel free to share and list your own automation python bot script on the project github project page with your fresh good results for others to try !
Related
- [My steemit announcement: https://steemit.com/utopian-io/@aro.steem/dice-roller-bot-python-primedice)
Proof of Work Done
https://github.com/nnmix/py-magicdice-bot/blob/master/script.py
Thank you for your contribution @aro.steem.
After reviewing your tutorial we suggest the following points listed below:
The structure of your tutorials is a bit confusing. See other tutorials that are placed in utopian to see how they structure the tutorials.
We suggest you explain in more detail all the steps that you describe in your tutorial.
Your tutorial is quite short for a good tutorial. We recommend you aim for capturing at least 2-3 concepts.
We suggest that in your next contribution put a title with more key words about what you will explain in the tutorial.
Thank you for your work in developing this tutorial.
Looking forward to your upcoming tutorials.
Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.
To view those questions and the relevant answers related to your post, click here.
Need help? Chat with us on Discord.
[utopian-moderator]
Thank you, if this is a developer / coding tutorial is there another tag to use? It will be better for developers to understand than other users.
Thank you for your review, @portugalcoin! Keep up the good work!
awesome, i have been using macros but will give it a try, always want to keep learning
Yeah i was thinking about an alliance to break the dice, automated with profit sharing, are you a developer?
Not a developer, Im IT infrastructure
Posted using Partiko Android
Nice write up and contribution buddy. I will like to give it try
Good job!
Hi @aro.steem!
Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server
Hey, @aro.steem!
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!
Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!
Dear @aro-steem, but when i modified this file with my own rules, what i should do with it to make it running on chrome browser?
nice ! you can try script with us too =)
🚀 🌕
Moon your steem everyday ! Instant Dividend payout after every game. chance to WIN 235,318 steemies every round. Participate in Players Upvote round (every 144 mins) worth $0.75
moonSTEEM.com