1.9.15 • Published 3 months ago

injective-vue v1.9.15

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

injective-vue

install

npm install injective-vue

Table of contents

Usage

RPC Clients

import { injective } from "injective-vue";

const { createRPCQueryClient } = injective.ClientFactory;
const client = await createRPCQueryClient({ rpcEndpoint: RPC_ENDPOINT });

// now you can query the cosmos modules
const balance = await client.cosmos.bank.v1beta1.allBalances({
  address: "inj1addresshere",
});

// you can also query the injective modules
const balances = await client.injective.exchange.v1beta1.exchangeBalances();

Composing Messages

Import the injective object from injective-vue.

import { injective } from "injective-vue";

const { createSpotLimitOrder, createSpotMarketOrder, deposit } =
  injective.exchange.v1beta1.MessageComposer.withTypeUrl;

Auction Messages

const { bid } = injective.auction.v1beta1.MessageComposer.withTypeUrl;

Exchange Messages

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,
} = injective.exchange.v1beta1.MessageComposer.withTypeUrl;

Insurance Messages

const { createInsuranceFund, requestRedemption, underwrite } =
  injective.insurance.v1beta1.MessageComposer.withTypeUrl;

OCR Messages

const {
  acceptPayeeship,
  createFeed,
  fundFeedRewardPool,
  setPayees,
  transferPayeeship,
  transmit,
  updateFeed,
  withdrawFeedRewardPool,
} = injective.ocr.v1beta1.MessageComposer.withTypeUrl;

Oracle Messages

const {
  relayBandRates,
  relayCoinbaseMessages,
  relayPriceFeedPrice,
  relayProviderPrices,
  requestBandIBCRates,
} = injective.oracle.v1beta1.MessageComposer.withTypeUrl;

Peggy Messages

const {
  cancelSendToEth,
  confirmBatch,
  depositClaim,
  eRC20DeployedClaim,
  requestBatch,
  sendToEth,
  setOrchestratorAddresses,
  submitBadSignatureEvidence,
  valsetConfirm,
  valsetUpdateClaim,
  withdrawClaim,
} = injective.peggy.v1.MessageComposer.withTypeUrl;

CosmWasm Messages

import { cosmwasm } from "injective-vue";

const {
  clearAdmin,
  executeContract,
  instantiateContract,
  migrateContract,
  storeCode,
  updateAdmin,
} = cosmwasm.wasm.v1.MessageComposer.withTypeUrl;

IBC Messages

import { ibc } from "injective-vue";

const { transfer } = ibc.applications.transfer.v1.MessageComposer.withTypeUrl;

Cosmos Messages

import { cosmos } from "injective-vue";

const {
  fundCommunityPool,
  setWithdrawAddress,
  withdrawDelegatorReward,
  withdrawValidatorCommission,
} = cosmos.distribution.v1beta1.MessageComposer.fromPartial;

const { multiSend, send } = cosmos.bank.v1beta1.MessageComposer.fromPartial;

const {
  beginRedelegate,
  createValidator,
  delegate,
  editValidator,
  undelegate,
} = cosmos.staking.v1beta1.MessageComposer.fromPartial;

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 Signing Client

Use SigningClient.connectWithSigner and pass in the signer options for injective to get your SigningClient:

import { SigningClient } from "@interchainjs/cosmos/signing-client";
import { defaultSignerOptions } from "@interchainjs/injective/defaults";

const signingClient = await SigningClient.connectWithSigner(
  await getRpcEndpoint(),
  new AminoGenericOfflineSigner(aminoOfflineSigner),
  {
    signerOptions: defaultSignerOptions.Cosmos,
  }
);

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 signingClient.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 signing client, you can do so by following the example below:

import {
    cosmosAminoConverters,
    cosmosProtoRegistry,
    cosmwasmAminoConverters,
    cosmwasmProtoRegistry,
    ibcProtoRegistry,
    ibcAminoConverters,
    injectiveAminoConverters,
    injectiveProtoRegistry
} from 'injective-vue';

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 SigningClient.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.

1.9.15

3 months ago

1.9.14

4 months ago

1.9.13

4 months ago

1.9.12

4 months ago

1.9.11

4 months ago

1.9.10

4 months ago

1.9.8

4 months ago

1.9.7

4 months ago

1.9.6

4 months ago

1.9.5

4 months ago

1.9.4

4 months ago

1.9.3

4 months ago

1.9.2

5 months ago

1.9.1

5 months ago

1.9.0

5 months ago

1.8.3

5 months ago

1.8.2

5 months ago

1.8.1

5 months ago

1.8.0

5 months ago

1.7.8

5 months ago

1.7.6

5 months ago

1.7.5

5 months ago

1.7.1

5 months ago

1.7.0

5 months ago

1.6.5

6 months ago

1.6.4

6 months ago

1.6.3

6 months ago

1.6.2

6 months ago

1.6.1

6 months ago

0.0.1-beta.30

6 months ago