Skip to content

Tutorial #1. (Blueprint version) Basic plugin usage.

Lazar Prijović edited this page Dec 10, 2021 · 2 revisions

In this tutorial we'll show you how to use basic functionality of Stratis Unreal plugin: create a wallet, check your balance and unspent transaction outputs (UTXOs), and send coins to another address.

Of we go!

Prerequisite

You need to setup your project and Stratis Unreal Plugin within it. If you looking for a tutorial about basic project setup, please check our tutorial #0.

Setting up StratisUnrealManager and creating a wallet

First of all, we need to setup StratisUnrealManager to be able to use all of the API methods provided by plugin.

Let's click on Blueprints menu in the toolbar and click Open Level Blueprint.

Menu

Now we see blueprint editor, let's create a variable stratisManager with type Stratis Unreal Manager.

Also, let's create a function called InitializeStratisUnrealManager, where we will define initialization logic for a our manager.

Components

Define InitializeStratisUnrealManager like below:

Object construction

Now we're going to set up base URL, network and wallet mnemonic.

Let's walk through the parameters:

  1. Mnemonic. Mnemonic is a sequence of words used to define private key of your wallet. You can create mnemonic using just a pen, a papper and a dice, or using a various of a hardware & software mnemonic generators.

  2. Base Url. To use Stratis Unreal Plugin, you need a full node to be running locally or remotely. Find your node's address (IP or domain) if you're running remote node, or use http://localhost:44336 if you're running your node locally.

  3. Network. The network you want to operate on. Use Cirrus and CirrusTest for production and testing respectively.

The last thing we need to do is call our new function Initialize Stratis Manager on BeginPlay event:

Initialization event

Getting a wallet balance

Now let's learn how we can get a balance of our wallet.

First, let's make a function for printing balance response to screen. Implement a blueprint like below:

Print balance

Note: Value has a type of FUInt64.

Now, let's make very similar function for the Error type:

Print error

Well, now we can actually call GetBalance function and await result. Add GetBalance to the event graph (right after manager initialization or after delay like in example) and set its Delegate and Error Delegate fields to custom events via Get Custom Event.

Bind delegate

Bind newly created events to the functions we defined: Print Balance and Print Error.

Desired event graph is shown below (Delay node is not necessary):

Get balance final scheme

Now, just press Play key and balance will be printed on your screen & debug console.

Getting unspent transaction outputs

Okay, now we will try to find unpsent transaction outputs for our wallet.

At first, let's create a method Print UTXOs and add input parameter UTXOs with type Array of UTXO. Now we're going to iterate over UTXO's array using For Each Loop node:

Iterate over UTXOs

Now let's just print every UTXO using Break... and Format Text nodes:

Print UTXOs function

We are almost done. Now we just need to call Get Coins node like we did for Get Balance node, and use functions (Print UTXOs and Print Error) we made previously. Final scheme is shown below:

Print UTXOs scheme

Sending coins & waiting for a receipt

Now let's try to implement a more complex logic: send some coins and await for transaction's receipt.

At first, add Send Coins Transaction node and set its inputs:

  • Destination address: in this example we're using tD5aDZSu4Go4A23R7VsjuJTL51YMyeoLyS for Cirrus Test network
  • Money: amount of satoshis we want to send. Let's send 10.000 satoshis (= 0.0001 STRAX).

Send Coins

And now we need to join Transaction ID output of TransactionSent event to Transaction ID input of Wait Till Receipt Available node.

At last, add some printing logic to see when receipt is available, and we're done!

Await receipt

(See this scheme on blueprintue.com)

What's next?

In this tutorial we've learned how to use some core plugin's functions: get balance, send coins and wait for receipt. In next tutorial we'll cover more advanced functionality of plugin: sending no-op transactions and interacting with smart contracts.

If you found a problem, you can open an issue on project's Github page. If you still have a questions, feel free to ask them in our Discord channel.

Stay tuned!