Steem Developer Portal

We will learn how to allocate a percentage for withdrawal to other accounts using Steemconnect as well as with the client-side signing method. This tutorial runs on the main Steem blockchain. Therefore, any accounts used here will affect real funds on the live network. Use with caution.

Intro

This tutorial will demonstrate a few functions such as querying account by name and determining the vesting balance of the related account. This will allow us to set “withdraw routes” to other accounts with a percent selection and auto power up function. This feature is quite useful if you want to withdraw a portion of your STEEM to a separate account or POWER UP other accounts as you withdraw from one account.

1. App setup

Below, we have dsteem pointing to the production network with the proper chainId, addressPrefix, and endpoint. There is a public/app.js file which holds the Javascript segment of this tutorial. In the first few lines we define the configured library and packages:

constdsteem=require('dsteem');letopts={};//connect to production serveropts.addressPrefix='STM';opts.chainId='0000000000000000000000000000000000000000000000000000000000000000';//connect to server which is connected to the network/productionconstclient=newdsteem.Client('https://api.steemit.com');

2. Get account routes

After the account name field is provided, using the Get withdraw routes button, we can fetch the current withdraw routes, if they exist. The related HTML input forms can be found in the index.html file. The values are pulled from that screen with the following:

3. Fill form

After we have fetched the account data, we will show a list of current routes, if they exist, and display information to the user about how many much they can apply to other accounts.

letinfo='';letsum=0;if(_account.length>0){for(vari=0;i<_account.length;i++){info+=`${_account[i].to_account} - ${_account[i].percent/100}%<br>`;sum+=_account[i].percent/100;}}else{info+=`No route is available!<br>`;}info+=`You can set ${100-sum}% remaining part to other accounts!`;document.getElementById('accInfo').innerHTML=info;

Previous routes can be overwritten by changing and submitting a new transaction to the same account.

4. Set withdraw route

We have two options on how to Power down: Steemconnect and client-side signing. Since this action requires Active authority, both client-side and Stemconnect signing will require the Active Private key to sign the transaction. The transaction submission function appears as follows: