Coder Social home page Coder Social logo

js-core's Introduction

@sei-js/core

This project provides helpful javascript functions for developing with Sei written in Typescript.

Getting Started

Tutorial

For an in depth ReactJS tutorial please see our documentation.

Installation

yarn add @sei-js/core

Wallet Connection

This package is officially supported by the following wallets; one of which is required for front end development.

Basic wallet connection

import { connect } from '@sei-js/core/wallet';

const { accounts, offlineSigner } = connect('leap');

Connect to a custom node

If you need to connect to a custom node, chain, or simply use a specific rest/rpc url, the connect() function contains optional inputs for these values.

import { connect } from '@sei-js/core/wallet';

const { accounts, offlineSigner } = connect('keplr', 'atlantic-1', 'https://example-rest.com', 'https://example-rpc.com');

List of officially supported wallets

SUPPORTED_WALLETS contains the walletKeys which are the first input to the connect() function and are helpful to display wallet options in your UI.

import { SUPPORTED_WALLETS } from '@sei-js/core/wallet';

console.log(SUPPORTED_WALLETS); // [{ windowKey: 'keplr' }, { windowKey: 'leap' }, { windowKey: 'falcon' }, { windowKey: 'coin98' }]

Query Client

The proto query client is used to query data from modules. For a comprehensive list of all endpoints available please see our proto package.

import { QueryClient } from '@sei-js/core';

const queryClient = await QueryClient.getQueryClient('https://example-rpc.com');

// Getting the market summary from the Sei dex module
queryClient.seiprotocol.seichain.dex.getMarketSummary(params)

// Getting user balances from the Cosmos bank module
queryClient.cosmos.bank.v1beta1.allBalances(params)

Signing Client

The signing client provides a way to sign and broadcast transactions on Sei.

Use getSigningClient to get your SigningStargateClient, with the Sei proto/amino messages loaded in.

Token transfer

import { SigningClient, Wallet } from '@sei-js/core';

const { accounts, offlineSigner } = Wallet.connect('leap');

const signingStargateClient = await SigningClient.getSigningClient({
  RPC_ENDPOINT,
  offlineSigner
});

const fee = calculateFee(100000, GasPrice.fromString('1usei'));
const transferAmount = { amount: SEND_AMOUNT, denom: TOKEN_DENOM };

const sendResponse = await signingStargateClient.sendTokens(accounts[0], DESTINATION_ADDRESSS, [transferAmount], fee);

IBC Token transfer

import { SigningClient, Wallet } from '@sei-js/core';

const { accounts, offlineSigner } = Wallet.connect('leap');

const signingStargateClient = await SigningClient.getSigningClient({
  RPC_ENDPOINT,
  offlineSigner
});

const fee = calculateFee(100000, GasPrice.fromString('1usei'));
const transferAmount = { amount: SEND_AMOUNT, denom: TOKEN_DENOM };

const ibcResponse = await signingStargateClient.sendIbcTokens(accounts[0].address, DESTINATION_ADDRESSS, transferAmount, 'transfer', CHANNEL_ID, undefined, undefined, fee)

Execute a contract (mint)

import { SigningClient, Wallet } from '@sei-js/core';

const { accounts, offlineSigner } = Wallet.connect('leap');

const signingStargateClient = await SigningClient.getSigningClient({
  RPC_ENDPOINT,
  offlineSigner
});

const account = accounts[0];
const mintMsg = { mint: {} };

const msg = {
   typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
   value: {
      sender: account.address,
      contract: CONTRACT_ADDR,
      msg: toUtf8(JSON.stringify(mintMsg)),
      funds: [],
   }
}

const mintResponse = await signingStargateClient.signAndBroadcast(account.address, [msg], fee);

Related packages

  • @sei-js/react - A react helper library for common @sei-js/core functions
  • @sei-js/proto - TypeScript library for Sei protobufs generated using Telescope

Examples

Documentation

js-core's People

Contributors

besated avatar codebycarson avatar suujia avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.