Hello, Griptape
In this landing section, we walk you step by step through a basic implementation using Griptapejs and its main APIs.
Overview
When you finish this Hello Griptape you will have a web app connected to pulsar-2
with the ability to get the user's balance and address, as well as a button to connect in case the user hasn't connected yet.
Checkout the full example in our repo here
Requirements
In order to go through this tutorial you'll need to have a Vue app created. You can find how to do it here. Also, install your dependencies and install Griptape.
Getting started
This tutorial consist of these steps.
Grip an application.
Bootstrap the application.
Import neccesary APIs.
Get and render the user's address and balance.
Grip an application
Grip
an application means involved our app into Griptape. This helps Griptape to control the different states an application can go through, trigger events, get balances and wallet address properly. In order to grip the application go to src/main.js
and import gripApp
and getKeplrAccountProvider
from @stakeordie/griptape.js
as the follow.
We assumed you are using Keplr as wallet. Griptape has only support with Keplr at this point. The Griptape team is working looking froward to support as many wallets as the Cosmos Ecosystem requires
Now, as you may know we need a REST URL to connect to, let's add it.
Ok, we good. now let's get Keplr provider.
We are almost get it, now we going to move our Vue app into a function, as the example below.
Now we just need to execute gripApp
from Griptape as the following code.
Bootstrap your application
Now that we have your gripped our application we need to bootstrap it. Bootstrap creates a signing client
able to encrypt and decrypt transactions. If you don't bootstrap the app we won't be able to get the wallet address and execute messages.
Now on, let's move to start working in src/App.vue
. As our first step we need to import bootstrap
api from @stakeordie/griptape.js
. Copy the example below.
Then we are going to create a util function called connect
and paste into methods
object.
Right next to it just create a button and add the function.
Import neccesary APIs from Griptape
Now as we want to get our SCRT
balance we need to import getNativeCoinBalance
from Griptape. getAddress
for getting the wallet address. onAccountAvailable
is part of our events API triggers a function when bootstrap API is executed (more info in hello-events
). And we also need a util function called coinConvert
is used to parsed any balance to human decimals readable. Our Griptape final imports should look like the following.
Get and render the user's address and balance
Let's get our hands dirty a bit! It's time to actually show something interesting for example the balance and address of the wallet. First let's set our data structure.
Next, let's create a re-usable function to get the native balance, this function should be in the methods
object.
Now, we are going to add one of our events API onAccountAvailable
to get the balance and address when the user connects its wallet.
Finally just show the information.
Checkout the full example in our repo here
Last updated