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
  • Add a permit
  • Use a permit with the contracts API
  1. Using Viewing Keys and Permits

Managing Permits

PreviousUsing Keplr with GriptapeNextHandling Events

Last updated 3 years ago

Permits are stored in local storage inside an object calledgriptape.js

A permit is a free authentication message from a certain public address, like a wallet signature, permits are stored locally so you don't need to re-generate a permit.

Add a permit

To create a permit, we must first import in our application permitManager from @stakeordie/griptape.js.

import { permitManager } from '@stakeordie/griptape.js';

Next, we're going to use the permitManager for this we use the add function, to which we're going to pass our contract and a permissions array.

await permitManager.add(myContract, ["balance"]);

You can notice that within the createPermit function we are also using permitManager.get() this function returns a boolean indicating whether or not this account has a permit. In this case it already has it and we add it to the setIsPermit variable.

Use a permit with the contracts API

To learn more about contract definitions, click .

Here is an example of how to use a permit in our contract definition, first we must import the APIs thet we require.

import {
    createContract,
    snip20Def,
    extendContract
  } from '@stakeordie/griptape.js';
  

Now we create myContract_permit object, where we add the query called getBalance wich receives a permit object and returns in this case the query and the permit.

  const myContract_permit = {
    queries: {
      getBalance({ permit }) {
        const query = { balance: {} }
        return {
          with_permit: { query, permit }
        }
      }
    }
  }

Finally we export and extend our contract.

export const sscrt = createContract({
    at: 'secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg',
    definition: extendContract(snip20Def, myContract_permit)
  });
🔑
here