New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

injectivejs

Package Overview
Dependencies
Maintainers
0
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

injectivejs

Injectivejs is a JavaScript library for interacting with injective sdk.

  • 1.9.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
246
increased by24.87%
Maintainers
0
Weekly downloads
 
Created
Source

InjectiveJS

install

npm install injectivejs

Table of contents

Usage

RPC Clients

import { createQueryRpc } from "@interchainjs/cosmos/utils";
import { createGetAllBalances } from "injectivejs/cosmos/bank/v1beta1/query.rpc.func";
import { createGetExchangeBalances } from "injectivejs/injective/exchange/v1beta1/query.rpc.func";

{ getRpcEndpoint } = useChain("osmosis");

const endpoint = await getRpcEndpoint();
const rpc = createQueryRpc(endpoint);

// get the tree shakable helper functions using the rpc client
const getAllBalances = createGetAllBalances(rpc);

// now you can query the cosmos modules
const balance = await getAllBalances({
  address: "inj1addresshere",
});

// you can also query the injective modules
const getExchangeBalances = createGetExchangeBalances(rpc);
const exchangeBalance = await getExchangeBalances({});

Tx Helpers

For tx messages, there're helper functions to sign and broadcast messages:

For more detailed usage on how to use these functions, please see the starship tests in the networks/injective repo

There're also react and vue hooks for helper functions. Please see injective-react and injective-vue repos for more information.

import {
  createDeposit,
  createLiquidatePosition,
  createActivateStakeGrant,
} from "injectivejs/injective/exchange/v1beta1/tx.rpc.func";
Auction
import { createBid } from "injectivejs/injective/auction/v1beta1/tx.rpc.func";
Exchange
import {
  createActivateStakeGrant,
  createAdminUpdateBinaryOptionsMarket,
  createAuthorizeStakeGrants,
  createBatchCancelBinaryOptionsOrders,
  createBatchCancelDerivativeOrders,
  createBatchCancelSpotOrders,
  createBatchCreateDerivativeLimitOrders,
  createBatchCreateSpotLimitOrders,
  createBatchUpdateOrders,
  createCancelBinaryOptionsOrder,
  createCancelDerivativeOrder,
  createCancelSpotOrder,
  createCreateBinaryOptionsLimitOrder,
  createCreateBinaryOptionsMarketOrder,
  createCreateDerivativeLimitOrder,
  createCreateDerivativeMarketOrder,
  createCreateSpotLimitOrder,
  createCreateSpotMarketOrder,
  createDecreasePositionMargin,
  createDeposit,
  createEmergencySettleMarket,
  createExternalTransfer,
  createIncreasePositionMargin,
  createInstantBinaryOptionsMarketLaunch,
  createInstantExpiryFuturesMarketLaunch,
  createInstantPerpetualMarketLaunch,
  createInstantSpotMarketLaunch,
  createLiquidatePosition,
  createPrivilegedExecuteContract,
  createRewardsOptOut,
  createSubaccountTransfer,
  createUpdateDerivativeMarket,
  createUpdateParams,
  createUpdateSpotMarket,
  createWithdraw,
} from "injectivejs/injective/exchange/v1beta1/tx.rpc.func";
Insurance
import {
  createCreateInsuranceFund,
  createRequestRedemption,
  createUnderwrite,
} from "injectivejs/injective/insurance/v1beta1/tx.rpc.func";
OCR
import {
  createAcceptPayeeship,
  createCreateFeed,
  createFundFeedRewardPool,
  createSetPayees,
  createTransferPayeeship,
  createTransmit,
  createUpdateFeed,
  createWithdrawFeedRewardPool,
} from "injectivejs/injective/ocr/v1beta1/tx.rpc.func";
Oracle
import {
  createRelayBandRates,
  createRelayCoinbaseMessages,
  createRelayPriceFeedPrice,
  createRelayProviderPrices,
  createRelayPythPrices,
  createRelayStorkMessage,
  createRequestBandIBCRates,
} from "injectivejs/injective/oracle/v1beta1/tx.rpc.func";
Peggy
import {
  createBlacklistEthereumAddresses,
  createCancelSendToEth,
  createConfirmBatch,
  createDepositClaim,
  createERC20DeployedClaim,
  createRequestBatch,
  createRevokeEthereumBlacklist,
  createSendToEth,
  createSetOrchestratorAddresses,
  createSubmitBadSignatureEvidence,
  createValsetConfirm,
  createValsetUpdateClaim,
  createWithdrawClaim,
} from "injectivejs/injective/peggy/v1/msgs.rpc.func";
CosmWasm
import {
  createExecuteContract,
  createClearAdmin,
  createInstantiateContract,
  createInstantiateContract2,
  createMigrateContract,
  createPinCodes,
  createRemoveCodeUploadParamsAddresses,
  createStoreAndInstantiateContract,
  createStoreCode,
  createSudoContract,
  createUnpinCodes,
  createUpdateAdmin,
  createUpdateContractLabel,
  createUpdateInstantiateConfig,
  createAddCodeUploadParamsAddresses,
  createStoreAndMigrateContract,
} from "injectivejs/cosmwasm/wasm/v1/tx.rpc.func";
IBC
import { createTransfer } from "injectivejs/ibc/applications/transfer/v1/tx.rpc.func";
Cosmos
import {
  createFundCommunityPool,
  createCommunityPoolSpend,
  createDepositValidatorRewardsPool,
} from "injectivejs/cosmos/distribution/v1beta1/tx.rpc.func";

import {
  createSend,
  createMultiSend,
} from "injectivejs/cosmos/bank/v1beta1/tx.rpc.func";

import {
  createDelegate,
  createUndelegate,
  createCancelUnbondingDelegation,
  createCreateValidator,
} from "injectivejs/cosmos/staking/v1beta1/tx.rpc.func";

import {
  createDeposit,
  createSubmitProposal,
  createVote,
  createVoteWeighted,
} from "injectivejs/cosmos/gov/v1beta1/tx.rpc.func";

Composing Messages

Import the injective object from injectivejs.

import { MessageComposer } from "injectivejs/injective/exchange/v1beta1/tx.registry";

const { createSpotLimitOrder, createSpotMarketOrder, deposit } =
  MessageComposer.withTypeUrl;
Auction Messages
import { MessageComposer } from "injectivejs/injective/auction/v1beta1/tx.registry";

const { bid } = MessageComposer.withTypeUrl;
Exchange Messages
import { MessageComposer } from "injectivejs/injective/exchange/v1beta1/tx.registry";

const {
  adminUpdateBinaryOptionsMarket,
  batchCancelBinaryOptionsOrders,
  batchCancelDerivativeOrders,
  batchCancelSpotOrders,
  batchCreateDerivativeLimitOrders,
  batchCreateSpotLimitOrders,
  batchUpdateOrders,
  cancelBinaryOptionsOrder,
  cancelDerivativeOrder,
  cancelSpotOrder,
  createBinaryOptionsLimitOrder,
  createBinaryOptionsMarketOrder,
  createDerivativeLimitOrder,
  createDerivativeMarketOrder,
  createSpotLimitOrder,
  createSpotMarketOrder,
  deposit,
  exec,
  externalTransfer,
  increasePositionMargin,
  instantBinaryOptionsMarketLaunch,
  instantExpiryFuturesMarketLaunch,
  instantPerpetualMarketLaunch,
  instantSpotMarketLaunch,
  liquidatePosition,
  rewardsOptOut,
  subaccountTransfer,
  withdraw,
} = MessageComposer.withTypeUrl;
Insurance Messages
import { MessageComposer } from "injectivejs/injective/insurance/v1beta1/tx.registry";

const { createInsuranceFund, requestRedemption, underwrite } =
  MessageComposer.withTypeUrl;
OCR Messages
import { MessageComposer } from "injectivejs/injective/ocr/v1beta1/tx.registry";

const {
  acceptPayeeship,
  createFeed,
  fundFeedRewardPool,
  setPayees,
  transferPayeeship,
  transmit,
  updateFeed,
  withdrawFeedRewardPool,
} = MessageComposer.withTypeUrl;
Oracle Messages
import { MessageComposer } from "injectivejs/injective/oracle/v1beta1/tx.registry";

const {
  relayBandRates,
  relayCoinbaseMessages,
  relayPriceFeedPrice,
  relayProviderPrices,
  requestBandIBCRates,
} = MessageComposer.withTypeUrl;
Peggy Messages
import { MessageComposer } from "injectivejs/injective/peggy/v1/tx.registry";

const {
  cancelSendToEth,
  confirmBatch,
  depositClaim,
  eRC20DeployedClaim,
  requestBatch,
  sendToEth,
  setOrchestratorAddresses,
  submitBadSignatureEvidence,
  valsetConfirm,
  valsetUpdateClaim,
  withdrawClaim,
} = MessageComposer.withTypeUrl;
CosmWasm Messages
import { MessageComposer } from "injectivejs/cosmwasm/wasm/v1/tx.registry";

const {
  clearAdmin,
  executeContract,
  instantiateContract,
  migrateContract,
  storeCode,
  updateAdmin,
} = MessageComposer.withTypeUrl;
IBC Messages
import { MessageComposer } from "injectivejs/ibc/applications/transfer/v1/tx.registry";

const { transfer } = MessageComposer.withTypeUrl;
Cosmos Messages
import { MessageComposer } from "injectivejs/cosmos/distribution/v1beta1/tx.registry";

const {
  fundCommunityPool,
  setWithdrawAddress,
  withdrawDelegatorReward,
  withdrawValidatorCommission,
} = MessageComposer.fromPartial;
import { MessageComposer } from "injectivejs/cosmos/bank/v1beta1/tx.registry";

const { multiSend, send } = MessageComposer.fromPartial;
import { MessageComposer } from "injectivejs/cosmos/staking/v1beta1/tx.registry";

const {
  beginRedelegate,
  createValidator,
  delegate,
  editValidator,
  undelegate,
} = MessageComposer.fromPartial;
import { MessageComposer } from "injectivejs/cosmos/gov/v1beta1/tx.registry";

const { deposit, submitProposal, vote, voteWeighted } =
  cosmos.gov.v1beta1.MessageComposer.fromPartial;

Connecting with Wallets and Signing Messages

⚡️ For web interfaces, we recommend using interchain-kit. Continue below to see how to manually construct signers and clients.

Here are the docs on creating signers in interchain-kit that can be used with Keplr and other wallets.

Initializing the Stargate Client

Use getSigningInjectiveClient to get your SigningStargateClient, with the proto/amino messages full-loaded. No need to manually add amino types, just require and initialize the client:

import { InjSigningClient } from "@interchainjs/injective/signing-client";

signingClient = await InjSigningClient.connectWithSigner(
  await getRpcEndpoint(),
  new AminoGenericOfflineSigner(aminoOfflineSigner)
);

Creating Signers

To broadcast messages, you can create signers with a variety of options:

Broadcasting Messages

When you have your signing client, you can broadcast messages:

const msg = {
  typeUrl: MsgSend.typeUrl,
  value: MsgSend.fromPartial({
    amount: [
      {
        denom: "inj",
        amount: "1000",
      },
    ],
    toAddress: address,
    fromAddress: address,
  }),
};

const fee: StdFee = {
  amount: [
    {
      denom: "inj",
      amount: "864",
    },
  ],
  gas: "86364",
};
const response = await stargateClient.signAndBroadcast(address, [msg], fee);

All In One Example

For a comprehensive example of how to use InjectiveJS to send messages, please see the example here. This example demonstrates how to:

  • Initialize the client.
  • Create and sign messages.
  • Broadcast transactions.
  • Handle responses and errors.

The example provides a complete walkthrough of setting up the client, creating a message for sending tokens, and broadcasting the transaction to the Injective blockchain.

Follow the instructions in the example to set up your InjectiveJS client and start sending messages to the Injective blockchain.

Advanced Usage

If you want to manually construct a stargate client

import {
    cosmosAminoConverters,
    cosmosProtoRegistry,
    cosmwasmAminoConverters,
    cosmwasmProtoRegistry,
    ibcProtoRegistry,
    ibcAminoConverters,
    injectiveAminoConverters,
    injectiveProtoRegistry
} from 'injectivejs';

const signer: OfflineSigner = /* create your signer (see above)  */
const rpcEndpoint = 'https://rpc.cosmos.directory/injective'; // or another URL

const protoRegistry: ReadonlyArray<[string, GeneratedType]> = [
    ...cosmosProtoRegistry,
    ...cosmwasmProtoRegistry,
    ...ibcProtoRegistry,
    ...injectiveProtoRegistry
];

const aminoConverters = {
    ...cosmosAminoConverters,
    ...cosmwasmAminoConverters,
    ...ibcAminoConverters,
    ...injectiveAminoConverters
};

const registry = new Registry(protoRegistry);
const aminoTypes = new AminoTypes(aminoConverters);

const signingClient = await InjSigningClient.connectWithSigner(rpcEndpoint, signer);

signingClient.addEncoders(registry);
signingClient.addConverters(aminoTypes);

Developing

When first cloning the repo:

yarn
yarn build:dev

Codegen

Contract schemas live in ./contracts, and protos in ./proto. Look inside of scripts/inj.telescope.json and configure the settings for bundling your SDK and contracts into injectivejs:

yarn codegen

Publishing

Build the types and then publish:

yarn build
yarn publish

Interchain JavaScript Stack ⚛️

A unified toolkit for building applications and smart contracts in the Interchain ecosystem

CategoryToolsDescription
Chain InformationChain Registry, Utils, ClientEverything from token symbols, logos, and IBC denominations for all assets you want to support in your application.
Wallet ConnectorsInterchain Kitbeta, Cosmos KitExperience the convenience of connecting with a variety of web3 wallets through a single, streamlined interface.
Signing ClientsInterchainJSbeta, CosmJSA single, universal signing interface for any network
SDK ClientsTelescopeYour Frontend Companion for Building with TypeScript with Cosmos SDK Modules.
Starter KitsCreate Interchain Appbeta, Create Cosmos AppSet up a modern Interchain app by running one command.
UI KitsInterchain UIThe Interchain Design System, empowering developers with a flexible, easy-to-use UI kit.
Testing FrameworksStarshipUnified Testing and Development for the Interchain.
TypeScript Smart ContractsCreate Hyperweb AppBuild and deploy full-stack blockchain applications with TypeScript
CosmWasm ContractsCosmWasm TS CodegenConvert your CosmWasm smart contracts into dev-friendly TypeScript classes.

Credits

🛠 Built by Hyperweb (formerly Cosmology) — if you like our tools, please checkout and contribute to our github ⚛️

Disclaimer

AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED “AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.

No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.

Keywords

FAQs

Package last updated on 29 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc