-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56b91e1
commit 3da8ea2
Showing
4 changed files
with
390 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |