diff --git a/libs/injective-react/README.md b/libs/injective-react/README.md index 8316e058..0a87a1e9 100644 --- a/libs/injective-react/README.md +++ b/libs/injective-react/README.md @@ -22,29 +22,42 @@ npm install injective-react ## Table of contents - [injective-react](#injective-react) - - [Install](#install) + - [install](#install) - [Table of contents](#table-of-contents) -- [Usage](#usage) - - [RPC Clients](#rpc-clients) - - [Tx Helpers](#tx-helpers) - - Injective - - [Auction](#auction-messages) - - [Exchange](#exchange-messages) - - [Insurance](#insurance-messages) - - [OCR](#ocr-messages) - - [Oracle](#oracle-messages) - - [Peggy](#peggy-messages) - - Cosmos, CosmWasm, and IBC - - [CosmWasm](#cosmwasm-messages) - - [IBC](#ibc-messages) - - [Cosmos](#cosmos-messages) -- [Wallets and Signers](#connecting-with-wallets-and-signing-messages) - - [Stargate Client](#initializing-the-stargate-client) - - [Creating Signers](#creating-signers) - - [Broadcasting Messages](#broadcasting-messages) -- [Advanced Usage](#advanced-usage) -- [Developing](#developing) -- [Credits](#credits) + - [Usage](#usage) + - [RPC Clients](#rpc-clients) + - [Tx Hooks](#tx-hooks) + - [Tx Helpers](#tx-helpers) + - [Auction](#auction) + - [Exchange](#exchange) + - [Insurance](#insurance) + - [OCR](#ocr) + - [Oracle](#oracle) + - [Peggy](#peggy) + - [CosmWasm](#cosmwasm) + - [IBC](#ibc) + - [Cosmos](#cosmos) + - [Composing Messages](#composing-messages) + - [Auction Messages](#auction-messages) + - [Exchange Messages](#exchange-messages) + - [Insurance Messages](#insurance-messages) + - [OCR Messages](#ocr-messages) + - [Oracle Messages](#oracle-messages) + - [Peggy Messages](#peggy-messages) + - [CosmWasm Messages](#cosmwasm-messages) + - [IBC Messages](#ibc-messages) + - [Cosmos Messages](#cosmos-messages) + - [Connecting with Wallets and Signing Messages](#connecting-with-wallets-and-signing-messages) + - [Initializing the Stargate Client](#initializing-the-stargate-client) + - [Creating Signers](#creating-signers) + - [Broadcasting Messages](#broadcasting-messages) + - [All In One Example](#all-in-one-example) + - [Advanced Usage](#advanced-usage) + - [Developing](#developing) + - [Codegen](#codegen) + - [Publishing](#publishing) + - [Credits](#credits) + - [License](#license) ## Usage @@ -52,8 +65,8 @@ npm install injective-react ```js import { createQueryRpc } from "@interchainjs/cosmos/utils"; -import { createGetAllBalances } from "injective-react/cosmos/bank/v1beta1/query.rpc.func"; -import { createGetExchangeBalances } from "injective-react/injective/exchange/v1beta1/query.rpc.func"; +import { createGetAllBalances } from "injectivejs/cosmos/bank/v1beta1/query.rpc.func"; +import { createGetExchangeBalances } from "injectivejs/injective/exchange/v1beta1/query.rpc.func"; { getRpcEndpoint } = useChain("osmosis"); @@ -73,25 +86,68 @@ const getExchangeBalances = createGetExchangeBalances(rpc); const exchangeBalance = await getExchangeBalances({}); ``` +### Tx Hooks + +injective-react provides hooks for sending transactions. These hooks are built on top of the `useQuery` hook and the `useMutation` hook from `react-query`. The hooks are designed to be used with the `useDelegate` and `useGetValidators` functions from `injectivejs`. + +There's also an all in one example of how to use these hooks in the [all in one example](#all-in-one-example) section. + +```js +import { useDelegate } from "injective-react/cosmos/staking/v1beta1/tx.rpc.func"; +import { useGetValidators } from "injective-react/cosmos/staking/v1beta1/query.rpc.func"; + +const { + data, + isSuccess: isGetValidatorsDone, + isLoading: isGetValidatorsLoading, +} = useGetValidators({ + request: { + status: "BOND_STATUS_BONDED", + }, + options: { + context: defaultContext, + enabled: !validatorAddress, + }, + rpcClient, +}); + +const { mutate: delegate, isSuccess: isDelegateSuccess } = useDelegate({ + clientResolver: signingClient, + options: { + context: defaultContext, + onSuccess: (data: any) => { + console.log("onSuccess", data); + }, + onError: (error) => { + console.log("onError", error); + }, + }, +}); +``` + ### 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](https://github.com/cosmology-tech/interchainjs/tree/main/networks/injective/starship/__tests__) + +There're also react hooks for helper functions. Please see the [Tx Hooks](#tx-hooks) section. + ```js import { createDeposit, createLiquidatePosition, createActivateStakeGrant, -} from "injective-react/injective/exchange/v1beta1/tx.rpc.func"; +} from "injectivejs/injective/exchange/v1beta1/tx.rpc.func"; ``` -#### Auction Messages +#### Auction ```js -import { createBid } from "injective-react/injective/auction/v1beta1/tx.rpc.func"; +import { createBid } from "injectivejs/injective/auction/v1beta1/tx.rpc.func"; ``` -#### Exchange Messages +#### Exchange ```js import { @@ -130,20 +186,20 @@ import { createUpdateParams, createUpdateSpotMarket, createWithdraw, -} from "injective-react/injective/exchange/v1beta1/tx.rpc.func"; +} from "injectivejs/injective/exchange/v1beta1/tx.rpc.func"; ``` -#### Insurance Messages +#### Insurance ```js import { createCreateInsuranceFund, createRequestRedemption, createUnderwrite, -} from "injective-react/injective/insurance/v1beta1/tx.rpc.func"; +} from "injectivejs/injective/insurance/v1beta1/tx.rpc.func"; ``` -#### OCR Messages +#### OCR ```js import { @@ -155,10 +211,10 @@ import { createTransmit, createUpdateFeed, createWithdrawFeedRewardPool, -} from "injective-react/injective/ocr/v1beta1/tx.rpc.func"; +} from "injectivejs/injective/ocr/v1beta1/tx.rpc.func"; ``` -#### Oracle Messages +#### Oracle ```js import { @@ -169,10 +225,10 @@ import { createRelayPythPrices, createRelayStorkMessage, createRequestBandIBCRates, -} from "injective-react/injective/oracle/v1beta1/tx.rpc.func"; +} from "injectivejs/injective/oracle/v1beta1/tx.rpc.func"; ``` -#### Peggy Messages +#### Peggy ```js import { @@ -189,10 +245,10 @@ import { createValsetConfirm, createValsetUpdateClaim, createWithdrawClaim, -} from "injective-react/injective/peggy/v1/msgs.rpc.func"; +} from "injectivejs/injective/peggy/v1/msgs.rpc.func"; ``` -#### CosmWasm Messages +#### CosmWasm ```js import { @@ -212,79 +268,219 @@ import { createUpdateInstantiateConfig, createAddCodeUploadParamsAddresses, createStoreAndMigrateContract, -} from "injective-react/cosmwasm/wasm/v1/tx.rpc.func"; +} from "injectivejs/cosmwasm/wasm/v1/tx.rpc.func"; ``` -#### IBC Messages +#### IBC ```js -import { createTransfer } from "injective-react/ibc/applications/transfer/v1/tx.rpc.func"; +import { createTransfer } from "injectivejs/ibc/applications/transfer/v1/tx.rpc.func"; ``` -#### Cosmos Messages +#### Cosmos ```js import { createFundCommunityPool, createCommunityPoolSpend, createDepositValidatorRewardsPool, -} from "injective-react/cosmos/distribution/v1beta1/tx.rpc.func"; +} from "injectivejs/cosmos/distribution/v1beta1/tx.rpc.func"; import { createSend, createMultiSend, -} from "injective-react/cosmos/bank/v1beta1/tx.rpc.func"; +} from "injectivejs/cosmos/bank/v1beta1/tx.rpc.func"; import { createDelegate, createUndelegate, createCancelUnbondingDelegation, createCreateValidator, -} from "injective-react/cosmos/staking/v1beta1/tx.rpc.func"; +} from "injectivejs/cosmos/staking/v1beta1/tx.rpc.func"; import { createDeposit, createSubmitProposal, createVote, createVoteWeighted, -} from "injective-react/cosmos/gov/v1beta1/tx.rpc.func"; +} from "injectivejs/cosmos/gov/v1beta1/tx.rpc.func"; ``` -### Tx Hooks +### Composing Messages -You can use the hooks for every query and tx messages: +Import the `injective` object from `injectivejs`. ```js -import { useDelegate } from "injective-react/cosmos/staking/v1beta1/tx.rpc.func"; -import { useGetValidators } from "injective-react/cosmos/staking/v1beta1/query.rpc.func"; +import { MessageComposer } from "injectivejs/injective/exchange/v1beta1/tx.registry"; + +const { createSpotLimitOrder, createSpotMarketOrder, deposit } = + MessageComposer.withTypeUrl; +``` + +#### Auction Messages + +```js +import { MessageComposer } from "injectivejs/injective/auction/v1beta1/tx.registry"; + +const { bid } = MessageComposer.withTypeUrl; +``` + +#### Exchange Messages + +```js +import { MessageComposer } from "injectivejs/injective/exchange/v1beta1/tx.registry"; const { - data, - isSuccess: isGetValidatorsDone, - isLoading: isGetValidatorsLoading, -} = useGetValidators({ - request: { - status: "BOND_STATUS_BONDED", - }, - options: { - context: defaultContext, - enabled: !validatorAddress, - }, - rpcClient, -}); + 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; +``` -const { mutate: delegate, isSuccess: isDelegateSuccess } = useDelegate({ - clientResolver: signingClient, - options: { - context: defaultContext, - onSuccess: (data: any) => { - console.log("onSuccess", data); - }, - onError: (error) => { - console.log("onError", error); - }, - }, -}); +#### Insurance Messages + +```js +import { MessageComposer } from "injectivejs/injective/insurance/v1beta1/tx.registry"; + +const { createInsuranceFund, requestRedemption, underwrite } = + MessageComposer.withTypeUrl; +``` + +#### OCR Messages + +```js +import { MessageComposer } from "injectivejs/injective/ocr/v1beta1/tx.registry"; + +const { + acceptPayeeship, + createFeed, + fundFeedRewardPool, + setPayees, + transferPayeeship, + transmit, + updateFeed, + withdrawFeedRewardPool, +} = MessageComposer.withTypeUrl; +``` + +#### Oracle Messages + +```js +import { MessageComposer } from "injectivejs/injective/oracle/v1beta1/tx.registry"; + +const { + relayBandRates, + relayCoinbaseMessages, + relayPriceFeedPrice, + relayProviderPrices, + requestBandIBCRates, +} = MessageComposer.withTypeUrl; +``` + +#### Peggy Messages + +```js +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 + +```js +import { MessageComposer } from "injectivejs/cosmwasm/wasm/v1/tx.registry"; + +const { + clearAdmin, + executeContract, + instantiateContract, + migrateContract, + storeCode, + updateAdmin, +} = MessageComposer.withTypeUrl; +``` + +#### IBC Messages + +```js +import { MessageComposer } from "injectivejs/ibc/applications/transfer/v1/tx.registry"; + +const { transfer } = MessageComposer.withTypeUrl; +``` + +#### Cosmos Messages + +```js +import { MessageComposer } from "injectivejs/cosmos/distribution/v1beta1/tx.registry"; + +const { + fundCommunityPool, + setWithdrawAddress, + withdrawDelegatorReward, + withdrawValidatorCommission, +} = MessageComposer.fromPartial; +``` + +```js +import { MessageComposer } from "injectivejs/cosmos/bank/v1beta1/tx.registry"; + +const { multiSend, send } = MessageComposer.fromPartial; +``` + +```js +import { MessageComposer } from "injectivejs/cosmos/staking/v1beta1/tx.registry"; + +const { + beginRedelegate, + createValidator, + delegate, + editValidator, + undelegate, +} = MessageComposer.fromPartial; +``` + +```js +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 @@ -345,6 +541,19 @@ const fee: StdFee = { 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](https://github.com/cosmology-tech/create-cosmos-app/blob/main/examples/injective/components/SendMsg.tsx). This example demonstrates how to: + +- Initialize the Stargate 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](https://github.com/cosmology-tech/create-cosmos-app/tree/main/examples/injective) 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 diff --git a/libs/injective-vue/README.md b/libs/injective-vue/README.md index 9920710c..d07052ed 100644 --- a/libs/injective-vue/README.md +++ b/libs/injective-vue/README.md @@ -22,29 +22,30 @@ npm install injective-vue ## Table of contents - [injective-vue](#injective-vue) - - [Install](#install) + - [install](#install) - [Table of contents](#table-of-contents) - [Usage](#usage) - [RPC Clients](#rpc-clients) - [Composing Messages](#composing-messages) - - Injective - - [Auction](#auction-messages) - - [Exchange](#exchange-messages) - - [Insurance](#insurance-messages) - - [OCR](#ocr-messages) - - [Oracle](#oracle-messages) - - [Peggy](#peggy-messages) - - Cosmos, CosmWasm, and IBC - - [CosmWasm](#cosmwasm-messages) - - [IBC](#ibc-messages) - - [Cosmos](#cosmos-messages) -- [Wallets and Signers](#connecting-with-wallets-and-signing-messages) - - [Stargate Client](#initializing-the-stargate-client) + - [Auction Messages](#auction-messages) + - [Exchange Messages](#exchange-messages) + - [Insurance Messages](#insurance-messages) + - [OCR Messages](#ocr-messages) + - [Oracle Messages](#oracle-messages) + - [Peggy Messages](#peggy-messages) + - [CosmWasm Messages](#cosmwasm-messages) + - [IBC Messages](#ibc-messages) + - [Cosmos Messages](#cosmos-messages) +- [Connecting with Wallets and Signing Messages](#connecting-with-wallets-and-signing-messages) + - [Initializing the Stargate Client](#initializing-the-stargate-client) - [Creating Signers](#creating-signers) - [Broadcasting Messages](#broadcasting-messages) - [Advanced Usage](#advanced-usage) - [Developing](#developing) + - [Codegen](#codegen) + - [Publishing](#publishing) - [Credits](#credits) +- [License](#license) ## Usage