Skip to content

Commit

Permalink
added initial bot
Browse files Browse the repository at this point in the history
  • Loading branch information
AneilPatel05 committed Sep 4, 2018
1 parent 56b91e1 commit 3da8ea2
Show file tree
Hide file tree
Showing 4 changed files with 390 additions and 0 deletions.
4 changes: 4 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PROMOTER = <promoter steem account>
ACTIVE_PRIVATE_KEY = <ACTIVE PRIVATE KEY of PROMOTER>
TARGET_ACCOUNT = <Target Steem account>
TRANSFER_MEMO = <Memo for promotion>
71 changes: 71 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const dsteem = require('dsteem')
require('dotenv').load();

// bot is configured with enviroment variables

// the username of the promoter
const PROMOTER = process.env['PROMOTER'] || die('PROMOTER missing')
// the owner private key of the bot
const OWNER_PRIVATE_KEY = process.env['OWNER_PRIVATE_KEY'] || die('OWNER_PRIVATE_KEY missing')
// the target account to follow
const TARGET_ACCOUNT =process.env['TARGET_ACCOUNT'] || die('TARGET_ACCOUNT missing')
// Memo for Promotion
const TRANSFER_MEMO = process.env['TRANSFER_MEMO'] || die('TRANSFER_MEMO missing')

// setup the dsteem client, you can use other nodes, for example gtg's public node at https://gtg.steem.house:8090
const client = new dsteem.Client('https://gtg.steem.house:8090')

// deserialize the posting key (in wif format, same format as you find on the steemit.com interface)
const key = dsteem.PrivateKey.from(OWNER_PRIVATE_KEY)

// create a new readable stream with all operations, we use the 'latest' mode since
// we don't care about reversed block that much for a simple vote bot
// and this will make it react faster to the votes of it's master
const stream = client.blockchain.getOperationsStream({mode: dsteem.BlockchainMode.Latest})

console.log(`Following ${ TARGET_ACCOUNT } For New Transfers`)

// the stream will emit one data event for every operatio that happens on the steemit blockchain
stream.on('data', (operation) => {

// we only care about vote operations made by the user we follow
if (operation.op[0] == 'transfer') {
let transfer = operation.op[1]
if (transfer.to === TARGET_ACCOUNT) {
console.log(`${ transfer.from } sent money to ${ transfer.to }`)
//TODO - Check for Transfers from other exchange accounts and skip promotion

// broadcast the promotional transfer to the network
client.broadcast.transfer({
amount:'0.001 SBD',
from:PROMOTER,
to:transfer.from,
memo:TRANSFER_MEMO

},key).then(
console.log("promoted to "+transfer.from)
).catch((error) => {
console.warn('transfer failed', error)
})
}
if (transfer.from === TARGET_ACCOUNT) {
console.log(`${ transfer.from } sent money to ${ transfer.to }`)
//TODO - Check for Transfers to other exchange accounts and skip promotion

// finally broadcast the vote to the network
client.broadcast.transfer({
amount:'0.001 SBD',
from:PROMOTER,
to:transfer.from,
memo:TRANSFER_MEMO

},key).then(
console.log("promoted to "+transfer.from)
).catch((error) => {
console.warn('transfer failed', error)
})
}
}
})

function die(msg) { process.stderr.write(msg+'\n'); process.exit(1) }
299 changes: 299 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "bot",
"version": "1.0.0",
"description": "bot ",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"author": "aneilpatel",
"license": "ISC",
"dependencies": {
"dotenv": "^6.0.0",
"dsteem": "^0.9.0"
}
}

0 comments on commit 3da8ea2

Please sign in to comment.