Migrate your DAPPS using the api.steemit.com API to HIVE -- example: retrieve recovery account and last post time
In my previous tutorial I explained how to migrate your DAPPS from Steemit to Hive, if you use steemJs or dsteemJS.
If instead your website or NodeJs application is using plain fetches (or curls via shell.js) to the api.steemit.com API, you can now easily migrate your apps to HIVE simply changing the target endpoint from https://api.steemit.com to https://api.hive.blog !
Here is an example in which we fetch the data of an account and extract its recovery account and the last time the account published a post:
// ==========================================
var targetAccount = 'keys-defender';
var targetApi = 'api.hive.blog'; // WAS: 'api.steemit.com' <<<<<<<<<<<<<<<<<<<<<<
// ==========================================
var fetchAccountInfo = () => new Promise((resolve) => {
fetch(targetApi, {
body: `{"jsonrpc":"2.0", "method":"condenser_api.get_accounts", "params":[["${targetAccount}"]], "id":1}`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
method: 'POST',
})
.then(res => res.json())
.then((res) => {
const data = res.result[0];
resolve({
recoveryAccount: data.recovery_account,
lastPost: new Date(data.last_post),
});
});
});
fetchAccountInfo().then(console.log);
YOU CAN USE THE SAME PRINCIPLE FOR ALL THE OPERATIONS LISTED ON THE STEEMIT API DOCUMENTATION: https://developers.steem.io/apidefinitions
To quickly test this script in a browser, simply follow these steps:
{ NOTE: This script does not requires a pre-existing Steemit/Hive account or any private key so it's very safe to use. }
STEP 1
Open your favorite browser on any site (I strongly recommend using Brave browser for its speed and security) and open the DevTools (
Ctrl + Shift + J
on Linux/Windows and Cmd + Opt + J
on Mac)
STEP 2
- Copy & paste my script below in the Console
- Change the value of
targetAccount
(first line of the script) with your account name - Press enter.
Enjoy! =]
This post has received a 78.84 % upvote from @boomerang.
Just a little test.