Skip to content

initia-labs/amino-converter

Repository files navigation

@initia/amino-converter

Amino types and proto registry for initia chains


Installation

npm install @initia/amino-converter

Included Types

Usage

With Signing Stargate Client

import { SigningStargateClient } from '@cosmjs/stargate'
import { registry, aminoTypes } from '@initia/amino-converter'

const signingClient = await SigningStargateClient.connectWithSigner(
  '[RPC-URL]',
  signer, // Offline signer
  {
    registry,
    aminoTypes,
  }
)

Add Custom Types

import { Registry } from '@cosmjs/proto-signing'
import { AminoTypes, SigningStargateClient } from '@cosmjs/stargate'
import { protoRegistry, aminoConverters } from '@initia/amino-converter'

const registry = new Registry([...protoRegistry, ...customRegistry])

const aminoTypes = new AminoTypes({
  ...aminoConverters,
  ...customAminoConverters,
})

const signingClient = await SigningStargateClient.connectWithSigner(
  '[RPC-URL]',
  signer, // Offline signer
  {
    registry,
    aminoTypes,
  }
)

Generate Amino Converter With Custom Msg

If you need to use MsgExecuteMessages, MsgSubmitProposal and MsgSubmitTx with your custom messages, you need to register your custom messages to thier amino converter.

import { Registry } from '@cosmjs/proto-signing'
import { AminoTypes, SigningStargateClient } from '@cosmjs/stargate'
import {
  protoRegistry,
  aminoConverters,
  generateMsgExecuteMessagesAminoConverter,
  generateMsgSubmitProposalAminoConverter,
  generateMsgSubmitTxAminoConverter,
} from '@initia/amino-converter'

const registry = new Registry([...protoRegistry, ...customRegistry])

const msgExecuteMessagesAminoConverter =
  generateMsgExecuteMessagesAminoConverter(
    [...protoRegistry, ...customRegistry],
    {
      ...aminoConverters,
      ...customAminoConverters,
    }
  ) // register custom msg

const aminoTypes = new AminoTypes({
  ...aminoConverters,
  ...customAminoConverters,
  msgExecuteMessagesAminoConverter,
})

const signingClient = await SigningStargateClient.connectWithSigner(
  '[RPC-URL]',
  signer, // Offline signer
  {
    registry,
    aminoTypes,
  }
)

About

Amino types and proto registry for initia chains

Resources

Stars

Watchers

Forks

Packages

No packages published