Automating steem-engine with customJson()

It's no secret that I like to automate tasks when I can. It shifts where I consume my time, helps me learn about how things work under the hood and maybe saves me some time. My first steem programme is a Clerk Bot that helps me do mundane things like claim rewards, maintain balances, and power up. These simple tasks can form quite powerful actions when managing multiple accounts.

With the rise of steem-engine, it's time to look at adding some steem-engine capabilities to my clerk bot. Firstly my clerk bot is written in nodejs and runs on a NanoPi NEO 2 (Raspberry Pi clone). Clerk bot uses the steem-js library, which is quite out of date now, but it's not worth the effort to change to dsteem just yet. I actually prefer dsteem and use it for my @we-are (see @we-are-one for the blog) system. I'll try to remain somewhat language agnostic so the general principles can apply to whatever your chosen steem API library and language happen to be.

My first task is to create transfers from STEEM to STEEMP. That's easy enough, perform a transaction, see what it looks like on steemd and then figure out what needs to be changed.

eturnerx transfer 0.040 STEEM to steem-peg {"id":"ssc-mainnet1","json":{"contractName":"steempegged","contractAction":"buy","contractPayload":{}}}

Hmmm the memo contains some JSON but that looks like it should be the same for each transfer. I tried a transfer using the steem wallet with the JSON pasted into the memo and it worked. Okay, great. Now if I want to transfer STEEM to STEEMP I use:

const memo = '{"id":"ssc-mainnet1","json":{"contractName":"steempegged","contractAction":"buy","contractPayload":{}}}'
steem.broadcast.transfer(wif_active, from, 'steem-peg', amount, memo, function(err, result) {
console.log(err, result);
});

I purchased some ENG mining tokens staked them. BTW: This is not investment advice - you think for you. What I need to do is claim the mined ENG tokens periodically. This is something I'll want to automate so first, claim using the UI then use steemd to find the transaction.

eturnerx custom json
required_auths []
required_posting_auths

  1. eturnerx
    id scot_claim_token
    json {"symbol":"ENG"}

That looks easy enough. Another static transaction. I've never done Custom Json before and steem-js' documentation doesn't help understand what the parameters should be.

steem.broadcast.customJson(wif, requiredAuths, requiredPostingAuths, id, json, function(err, result) {
console.log(err, result);
});

The WIF required is the posting key. Okay, now let's see if we can find some other help. I found this post by @emrebeyler which talks about what to do for Python. This at least tells me what the data types are the Steem API will expect.

steem.broadcast.customJson(wif_posting, [], [steemaccountname], 'scot_claim_token', '{"symbol":"ENG"}', function(err,result) {
if(err) {
console.log('ERROR: @' + steemaccountname + ' claiming mined ENG steem-engine tokens');
console.log(JSON.stringify(err));
handletransactionerror();
} else {
console.log('@' + t[2] + ' claimed mined ENG steem-engine tokens');
handletransactionsuccess();
}});

Here's a snippet of my code. The second parameter is an empty set of brackets and the third encloses a string containing my account name into an array. The account name string should not start with @. Then, the id is 'scot_claim_token' and json is as above.
My clerk will run this once on startup and then once per day after that. I should never have to manually claim ENG tokens ever again!

I look forward to adding more steem-engine functionality in future. It looks like I might be earning some PALCoins so I think it might pay to automate moving them about and staking them too. We'll see.

I hope you found this brief overview helpful.

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center