sdk

package module
v1.58.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2025 License: Apache-2.0 Imports: 27 Imported by: 1

README ¶

Injective Protocol Golang SDK 🌟

codecov


📚 Getting Started

Clone the repository locally and install needed dependencies

$ git clone git@github.com:InjectiveLabs/sdk-go.git
$ cd sdk-go
$ go mod download

Run examples

# import pk into keyring if you use keyring
injectived keys unsafe-import-eth-key inj-user 5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e

# run chain example
go run examples/chain/bank/1_MsgSend/example.go

# run exchange example
go run examples/exchange/derivatives/4_Orderbook/example.go

Choose Exchange V1 or Exchange V2 queries

The SDK provides two different clients for interacting with the Injective Exchange:

  • ChainClient: Use this client if you need to interact with Exchange V1. This client maintains compatibility with the original exchange implementation and is suitable for existing applications that haven't migrated to V2 yet. Note that this client will not include any new endpoints added to the Exchange module - for access to new features, you should migrate to V2.

  • ChainClientV2: Use this client for all new applications or when you need to interact with Exchange V2 features. This client provides access to the latest exchange functionality and improvements, including all new endpoints added to the Exchange module.

Example usage:

// For Exchange V1
client := chainclient.NewChainClient(...)

// For Exchange V2
clientV2 := chainclient.NewChainClientV2(...)
Markets Assistant

The SDK provides a Markets Assistant to help you interact with markets in both V1 and V2. Here's how to create instances for each version:

// For Exchange V1 markets
marketsAssistant, err := chain.NewMarketsAssistant(ctx, client)  // ChainClient instance
if err != nil {
    // Handle error
}

// For Exchange V2 markets
marketsAssistantV2, err := chain.NewHumanReadableMarketsAssistant(ctx, clientV2)  // ChainClientV2 instance
if err != nil {
    // Handle error
}

The Markets Assistant provides helper methods to:

  • Fetch market information
  • Get market prices
  • Query orderbooks
  • Access market statistics

Make sure to use the correct version of the Markets Assistant that matches your ChainClient version to ensure compatibility. The V1 assistant (NewMarketsAssistant) will only work with V1 markets, while the V2 assistant (NewHumanReadableMarketsAssistant) provides access to V2 markets and their features.

Format Differences

There are important format differences between V1 and V2 endpoints:

  • Exchange V1: All values (amounts, prices, margins, notionals) are returned in chain format (raw numbers)
  • Exchange V2: Most values are returned in human-readable format for better usability:
    • Amounts, prices, margins, and notionals are in human-readable format
    • Deposit-related information remains in chain format to maintain consistency with the Bank module

This format difference is one of the key improvements in V2, making it easier to work with market data without manual conversion.

Updating Exchange API proto and client

$ make copy-exchange-client

(you have to clone this repo into ../injective-indexer)


Publishing Tagged Release

$ git add .
$ git commit -m "bugfix"
$ git tag -a v1.1.1
$ git push origin master --tags

⛑ Support

Reach out to us at one of the following places!


License

Copyright © 2020 - 2025 Injective Labs Inc. (https://injectivelabs.org/)

Originally released by Injective Labs Inc. under:
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

Functions ¶

func GenerateTypedDataAndVerifySignatureEIP712 ¶ added in v1.58.0

func GenerateTypedDataAndVerifySignatureEIP712(
	pubKey cryptotypes.PubKey,
	signerData authsigning.SignerData,
	sigData signing.SignatureData,
	tx authsigning.Tx,
) (*typeddata.TypedData, error)

VerifySignature verifies a transaction signature contained in SignatureData abstracting over different signing modes and single vs multi-signatures.

func WrapTxToEIP712AminoJSON ¶ added in v1.58.0

func WrapTxToEIP712AminoJSON(
	cdc codec.ProtoCodecMarshaler,
	tx authsigning.Tx,
	authSignerData *authsigning.SignerData,
	opts Web3ExtensionOptions,
) (typeddata.TypedData, error)

WrapTxToEIP712AminoJSON is an ultimate method that wraps aminojson-encoded Cosmos Tx JSON data into an EIP712-compatible request. All messages must be of the same type.

func WrapTxToEIP712LegacyAmino ¶ added in v1.58.0

func WrapTxToEIP712LegacyAmino(
	cdc codec.ProtoCodecMarshaler,
	tx authsigning.Tx,
	signerData *authsigning.SignerData,
	opts Web3ExtensionOptions,
) (typeddata.TypedData, error)

WrapTxToEIP712LegacyAmino is the method previously used to generate EIP712 typed data (until sdk v0.50)

func WrapTxToEIP712V2 ¶ added in v1.47.15

func WrapTxToEIP712WithSignBytes ¶ added in v1.58.0

func WrapTxToEIP712WithSignBytes(
	signBytes []byte,
	cdc codec.ProtoCodecMarshaler,
	chainID int64,
	msgs []cosmtypes.Msg,
	feePayer cosmtypes.AccAddress,
	timeoutHeight uint64,
) (typeddata.TypedData, error)

WrapTxToEIP712WithSignBytes wraps provided signBytes to EIP712 TypedData

Types ¶

type EIP712Wrapper ¶ added in v1.47.15

type EIP712Wrapper func(
	cdc codec.ProtoCodecMarshaler,
	tx authsigning.Tx,
	signerData *authsigning.SignerData,
	opts Web3ExtensionOptions,
) (typeddata.TypedData, error)

type Eip712SigVerificationDecorator ¶ added in v1.58.0

type Eip712SigVerificationDecorator struct {
	// contains filtered or unexported fields
}

Verify all signatures for a tx and return an error if any are invalid. Note, the Eip712SigVerificationDecorator decorator will not get executed on ReCheck.

CONTRACT: Pubkeys are set in context for all signers before this decorator runs CONTRACT: Tx must implement SigVerifiableTx interface

func NewEip712SigVerificationDecorator ¶ added in v1.58.0

func NewEip712SigVerificationDecorator(ak authante.AccountKeeper) Eip712SigVerificationDecorator

func (Eip712SigVerificationDecorator) AnteHandle ¶ added in v1.58.0

func (svd Eip712SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error)

type Web3ExtensionOptions ¶ added in v1.58.0

type Web3ExtensionOptions struct {
	ChainID     int64
	FeePayer    sdk.AccAddress
	FeePayerSig []byte
}

func GetWeb3ExtensionOptions ¶ added in v1.58.0

func GetWeb3ExtensionOptions(tx authsigning.Tx, signerData authsigning.SignerData) (Web3ExtensionOptions, error)

Directories ¶

Path Synopsis
chain
tm
ethereum
rpc
examples
chain/8_OfflineSigning command
example for how to sign tx offline, store to file and load + broadcast later
example for how to sign tx offline, store to file and load + broadcast later
exchange

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL