Manage Flags using Stellar Burrito

What is StellarBurrito?

StellarBurrito is a package available on npm.

This package’s aim is to simplify the use of stellar-sdk thanks simplified calls to the core library.

This project is open source and opens to PR so if you want to help take a look at the GitHub project!

This tutorial works on test-net, currently this library isn’t suitable for production use.


Let’s start

First of all, we need to create the project

chinaski@XPS:~/Desktop$ mkdir Medium-ManageFlags
chinaski@XPS:~/Desktop$ cd Medium-ManageFlags/
chinaski@XPS:~/Desktop/Medium-ManageFlags$ touch index.js
chinaski@XPS:~/Desktop/Medium-ManageFlags$ npm init

Then install stellar burrito package from npm

chinaski@XPS:~/Desktop/Medium-ManageFlags$ npm i stellarburrito --save

Now our project should be initialized properly!

Why we need flags?

Flags are used to set particular authorization level on an account.

According to Stellar’s official doc currently, there are three flags, used by issuers of assets.

  • Authorization required (0x1): Requires the issuing account to give other accounts permission before they can hold the issuing account’s credit.
  • Authorization revocable (0x2): Allows the issuing account to revoke its credit held by other accounts.
  • Authorization immutable (0x4): If this is set then none of the authorization flags can be set and the account can never be deleted.

Pretty cool right?

Actually, it’s also pretty simple!

Introduction

In this tutorial, we will use accountOptions and accountStatus of stellarburrito.
accountOptions.SetFlag allows you to set all of the 3 types of flag on an account given as input. 
Just pass account’s secretKey and the flag that you want to set (1 for Authorization required 2 for Authorization revocable 4 for Authorization Immutable).
accountStatus.getFlags return a json containing info about flags of the given account. Here an example :

{ auth_required: true,
 auth_revocable: false,
 auth_immutable: false }

Let’s start coding!

first of all, include stellar burrito in your project

Set authorization_required flag

This flag can be set passing 1 as a parameter to the setFlag function, as shown in the picture.

Let’s check if it works!

flags should contain

{ auth_required: true,
 auth_revocable: false,
 auth_immutable: false }

It works!

Now let’s clear this mess.

Clear Flag

flags can be cleared using accountOptions.clearFlags as shown in the picture

Here a full code for setting auth_required flag

WARNING! You should use catch blocks, I’ve omitted them to have a cleaner code for this tutorial

But what about other flags?

It’s simple, just replace the argument in setFlag and clearFlag function the Flag argument

for setting Authorization revocable

for Authorization immutable just replace 2 with 4

That’s it!

Reach me on keybase @andreaborio for any question!

Take a look at stellarburrito’s repo

Thanks for your attention