Griptape.js
  • What is Griptape.js?
  • 🛹Getting Started
  • 🚀Bootstrapping Your App
  • 🗞️Interacting with Contracts
    • Contract Definitions
      • More on Definitions
    • Creating Contract Clients
    • Built-In Definitions
    • Extending Contract Definitions
    • Contract Registry
    • Instantiating Contracts
  • 🔑Using Viewing Keys and Permits
    • Using the viewing key manager
    • Using Keplr with Griptape
    • Managing Permits
  • 🕢Handling Events
  • ⚒️Using Utilities
  • 🔀API Reference
    • Bootstrap
    • Contracts
    • Viewing Keys
    • Permits
    • Events
    • Utilities
  • 🐝Tricks Tutorials
    • React Tutorials
      • Hello, Griptape
      • Hello, Contracts
      • Hello, Events
      • Hello, Viewing Keys
      • Hello, Permits
      • Hello, Transactions
      • Hello, Mint
    • Vue Tutorials
      • Hello, Griptape
      • Hello, Contracts
      • Hello, Events
      • Hello, Viewing Keys
      • Hello, Permits
      • Hello, Transactions
      • Hello, Mint
  • 💾Hackathon
    • Welcome Packet
    • Getting Set Up
    • Glossary
Powered by GitBook
On this page
  • Numbers
  • Formatting
  • Accounts

Using Utilities

Griptape has many other utilities to help you solve some of the most common but non-trivial problems you will find while developing your application. Here we are going through some of them briefly.

Numbers

It is common in dApps to perform operations on big numbers. Most of these numbers are represented in strings, which for some cases formatting and handling a proper way for displaying them might cause some problems. For that you have a coinConvert function to help you manage those cases:

// Note this is part of griptape.js not griptpae-vue.js!
import { coinConvert } from '@stakeordie/griptape.js'
const bigNumber = '15000001645000'
coinConvert(bigNumber, 6, 'human') // 15000001.645
coinConvert(bigNumber, 6, 'human', 2) // 15000001.65
coinConvert(bigNumber, 6, 'machine') // 15000001645000

Formatting

Formatting addresses and viewing keys is very common in Secret Network dApps. bech32 can help abbreviate those:

import { bech32 } from '@stakeordie/griptape.js'
const address = 'secret1jajwgdsfv8e88utlgxjndlvcm8aldyn3ecsk72'
bech32(walletAddress, 16) // secret1j...n3ecsk72
bech32(walletAddress, 24) // secret1jajwg...aldyn3ecsk72

Accounts

Here are some features that will help you get information about the account that is connected to your app.

The getAddress() function is imported directly from '@stakeordie/griptape.js' and it's enough to declare a variable and assign the result of this function. getAddress() will help you know the address of the account connected to your application.

import { getAddress } from '@stakeordie/griptape.js'
const address = getAddress()

If you want to know the more information about the account connected to your application, the function getWalletInfo() should suffice.

import { getWalletInfo } from '@stakeordie/griptape.js'
const walletInfo = getWalletInfo()

To find out if you have an available account connected to your application, you can use the isAccountAvailable() function which will return a boolean value depending on the status of the account.

import { isAccountAvailable} from '@stakeordie/griptape.js'
const isAvailable = isAccountAvailable()
PreviousHandling EventsNextAPI Reference

Last updated 3 years ago

⚒️