LogoLogo
  • Persistence Hub
    • 👓Overview
    • 🌐Persistence Ecosystem
  • Begin & Explore
    • 🔏Wallet Setup
    • 📓Getting Your Persistence Address
    • 💰Acquiring $XPRT Tokens
  • Products
    • 🦾Persistence DEX (V1)
      • 📘Introduction
      • 📖Guides
        • 👨‍💼Managing Assets
        • 💱Trading Assets
        • 🚰Providing Liquidity
        • ⛓️Bonding/Unbonding Tokens
        • 🎉Claiming Rewards
        • 🏗️Creating New Pool
          • 🌀Metastable Pool
          • ⚖️Weighted Pool
          • 🧊Stable Swap Pool
      • 🏊‍♂️Pools
      • ⚡Instant LP Unbonding
      • 🎁Tradooor Rebate Program
      • 💰Fees
      • 🏆Rewards
      • ⚙️Technical Architecture
    • Bitcoin Cross-Chain Swaps (V2)
      • 🌟Introduction
      • 📚Fundamentals
        • 💱BTCfi
        • 🌉Bitcoin Layer 2s
        • Interoperability for BTCfi
        • 💡Intents for Blockchain Interoperability
      • 🔀Traditional Bridges vs. Intent-Based Swaps
      • ⚙️Product Mechanism
  • 💂Security
    • 📖Audits
  • Participate & Explore
    • $XPRT Token
      • 🛒Acquire
      • 📈Stake
      • 🏛️Governance
    • 🖥️Alternative Frontends
      • 🔃Hosting IPFS Versions with Pinata
      • 🤖IPFS Automation
    • 💼Wallets
    • 🔍Explorers
    • 💸Grants
  • Persistence Core-1 Chain
    • 🟢Running Nodes
      • Run a Local Node
      • Run a Testnet Node
      • Run a Mainnet Node
      • Node operations
        • State Sync
        • Run in the background
        • Cosmovisor upgrades
        • Manual upgrades
      • Seed & Peers
    • Public Infrastructure
      • Persistence Testnet
      • Endpoints
      • Snapshots & Archival Nodes
      • Faucets
      • Chain Registry
    • 🛡️Validators
      • Validate on Testnet
      • Validate on Mainnet
      • Validator Communication
    • 📡Relayers
      • IBC Channels
      • IBC Relayers
      • Relay on Mainnet
      • Relay on Testnet
    • 🫗Liquid Staking Module
      • For Validators
    • 📄Smart Contracts
      • Overview
      • Uploading a Contract
    • 👨‍💻Developer Tools
      • Persistence JS
      • Persistence SDK
    • ⚒️Community Tools
  • Community & Support
    • 🇹🇰Foundation Delegations
      • ➡️Round 1 - Closed
      • ➡️Round 2 - Closed
      • ⭐Bonus Delegation
      • ➡️Round 3 - Delegation Period Over
    • ⭕Coin-type Migration from 750 to 118
      • Persistence Wallet
      • Keplr Wallet
      • Ledger Hardware Wallet
      • Cosmostation Wallet
      • Coin98 Super Wallet
      • Math Wallet
      • Leap Wallet
      • Citadel Wallet
    • 🌎Geofencing on Persistence
    • 😍Connect & Follow
Powered by GitBook
On this page
  • Setup
  • Usage
  • Example
  • Gov Proposals

Was this helpful?

Edit on GitHub
  1. Persistence Core-1 Chain
  2. Developer Tools

Persistence JS

PreviousDeveloper ToolsNextPersistence SDK

Last updated 4 months ago

Was this helpful?

Setup

npm install persistenceonejs

Usage

PersistenceClient consists of a signingStargateClient and a SigningCowsmWasmClient, referred to as core and wasm respectively.

For querying use PersistenceClient.query, this gives you a tmclient. Usage for a tmclient for querying is based on cosmos-sdk i.e. query path is taken from module locations.

import { PersistenceClient } from "persistenceonejs";

const alice = await PersistenceClient.init(...mnemonic);
const codes = await alice.query.cosmwasm.wasm.v1.codes({});
console.log(codes);

Example

  • import { PersistenceClient, Cw20Contract } from "persistenceonejs";
    import { coins } from "@cosmjs/stargate";
    
    const alice = await PersistenceClient.init(...mnemonic);
    const [account] = await alice.wallet.getAccounts();
    const aliceaddress = account.address;
    const pstake =
      "persistence14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sjvz4fk"; //cw20 token address on chain
    const res = await alice.wasm.execute(
      aliceaddress,
      pstake,
      {
        transfer: {
          recipient: "persistence123em6jp7y96rtylp6tjk9r0dcescl0k4ccqvpu", //recipient address
          amount: "10",
        },
      },
      { amount: coins(2_000_000, "stake"), gas: "200000" },
    );
    console.log(res);
    {
      logs: [ { msg_index: 0, log: '', events: [Array] } ],
      height: 1354,
      transactionHash: 'B4789783E9FB89FC69AB38F38C3C670612041C7E1EFFB8DF22929681BD52FB4A',
      gasWanted: 200000,
      gasUsed: 75715
    }

    Query Balance

    const balance = await alice.wasm.queryContractSmart(pstake, {
      balance: { address: "persistence123em6jp7y96rtylp6tjk9r0dcescl0k4ccqvpu" },
    });
    console.log(balance);
    {
      balance: "13010";
    }
  • MsgSend A more flexible way to send transaction is by creating a Msg and brodcasting it. This is the preferd way for building large scale applications with multiple components.

    import { cosmos } from "persistenceonejs";
    const sendMsg = {
      typeUrl: "/cosmos.bank.v1beta1.tx.MsgSend",
      value: cosmos.bank.v1beta1.MsgSend.fromJSON({
        fromAddress: from,
        toAddress: to,
        amount: amount,
      }),
    };
    const res = await alice.core.signAndBroadcast(
      account.address,
      [sendMsg],
      { amount: [{ denom: "uxprt", amount: "10000" }], gas: "100" },
      "test send",
    );

Gov Proposals

NOTE: It is the default method for uploading your own contract to the persistence chain.

Send Tokens Use persistenceClient.wasm to send contracts via CW20 contract, persistenceClient.wasm is a SigningWasmClient so most of the functionalities are similar to @cosmjs/. The Signer for this example is a mnemonic wallet.

Please refer to for more information on how to use CosmWasm.

This method gives a lot more flexibility for an application, additional use case can be found in the .

This lets you upload and initiate a contract via Gov proposals.

👨‍💻
cosmwasm-stargate
cowmwasm
helpers
script
LogoGitHub - persistenceOne/persistenceJS: Client side JS libraries for persistenceSDK transaction generation, signing and broadcasting.GitHub
https://github.com/persistenceOne/persistenceJS#readme