diff --git a/.gitbook/README.md b/.gitbook/README.md
index 22a8c72d9..0335017be 100644
--- a/.gitbook/README.md
+++ b/.gitbook/README.md
@@ -21,3 +21,4 @@ _Note: Reading the Technical Concepts section after reading the overview below i
* [Core Modules](core-modules/) - In this section we are going to have a quick summary of the core modules on Injective and show examples of how to create some Messages (+ pack them into a transaction, sign them using a private key, and broadcast them on Injective) within these core modules.
* [Bridge](bridge/) - In this section, we are going to have a look at Injective's interoperability and explain how developers can utilize the Peggy bridge and the IBC bridge to bridge assets over to Injective.
* [Networks](readme/networks.md) - In this section, we will look at different (pre-defined) available Networks for developers to utilize while building dApps on top of Injective, allowing them to start building without the need to make their own infrastructure.
+* [Calculations](calculations/) - In this section, we will look at different calculations formula converting values between UI human-readable and chain format.
diff --git a/.gitbook/SUMMARY.md b/.gitbook/SUMMARY.md
index f2719e3af..f9fb2de00 100644
--- a/.gitbook/SUMMARY.md
+++ b/.gitbook/SUMMARY.md
@@ -3,15 +3,15 @@
* [Getting Started](README.md)
* [Technical Concepts](readme/technical-concepts.md)
* [Application Concepts](readme/application-concepts.md)
- * [Token Metadata](readme/token-metadata/README.md)
+ * [Assets (Token Metadata)](readme/token-metadata/README.md)
* [Creating Tokens](readme/token-metadata/creating-tokens.md)
* [Denom Client](readme/token-metadata/denom-client.md)
* [Networks](readme/networks.md)
* [CosmJs Support](readme/getting-started-cosmjs.md)
* [Wallet](wallet/README.md)
* [Accounts](wallet/wallet-accounts.md)
- * [Wallet Strategy](wallet/wallet-wallet-strategy.md)
* [Wallet Connections](wallet/wallet-connections.md)
+ * [Wallet Strategy](wallet/wallet-wallet-strategy.md)
* [Querying](querying/README.md)
* [Indexer](querying/querying-api/README.md)
* [Account](querying/querying-api/querying-indexer-account.md)
@@ -61,6 +61,7 @@
* [Core Modules](core-modules/README.md)
* [Auction](core-modules/auction.md)
* [AuthZ](core-modules/authz.md)
+ * [Feegrant](core-modules/feegrant.md)
* [Bank](core-modules/bank.md)
* [Distribution](core-modules/distribution.md)
* [Exchange](core-modules/exchange.md)
@@ -75,7 +76,8 @@
* [Ethereum](bridge/ethereum.md)
* [IBC](bridge/ibc.md)
* [Wormhole](bridge/wormhole.md)
-* [Contracts](contracts.md)
+* [Contracts](contracts/README.md)
+ * [Injective Name Service](contracts/injective-name-service.md)
* [Building dApps](building-dapps/README.md)
* [Configuring Nuxt](building-dapps/configuring-nuxt.md)
* [Configuring React](building-dapps/configuring-react.md)
@@ -83,3 +85,4 @@
* [Smart Contract](building-dapps/smart-contract.md)
* [DEX](building-dapps/dex.md)
* [Bridge](building-dapps/bridge.md)
+* [Calculations](calculations/README.md)
diff --git a/.gitbook/building-dapps/README.md b/.gitbook/building-dapps/README.md
index 574623606..f61e2611f 100644
--- a/.gitbook/building-dapps/README.md
+++ b/.gitbook/building-dapps/README.md
@@ -6,7 +6,15 @@ Injective is natively interoperable with several well-known blockchain networks,
Within this section we are going to explore configuring different UI frameworks to work with the `@injectivelabs` packages so you can start building decentralized applications on top of Injective. We are also going to showcase example (simple) dApps built on top of Injective.
+***
+### Create Injective dApp CLI tool
+
+The simplest way to start your journey on Injective is using our CLI tool. To do this, simply write this command and follow the instructions in your terminal!
+
+```bash
+$ npx @injectivelabs/create-injective-app
+```
### Configuration
@@ -15,7 +23,7 @@ Within this section we are going to explore configuring different UI frameworks
| [Configuring Nuxt](configuring-nuxt.md) | Configuring Nuxt 3.x + Vite |
| [Configuring React](configuring-react.md) | Configuring React 18 + Vite |
-
+***
### Dapps
diff --git a/.gitbook/calculations/README.md b/.gitbook/calculations/README.md
new file mode 100644
index 000000000..bebe608d5
--- /dev/null
+++ b/.gitbook/calculations/README.md
@@ -0,0 +1,10 @@
+# Calculations
+
+Here are some formula formatting values between the chain and UI human-readable.
+
+### Bridges Supported
+
+| Topic | Description |
+| ------------------------------------------------------- | --------------------------------------- |
+| [Market min price tick size](minPriceTickSize.md) | Minimum market order price tick size |
+| [Market min quantity tick size](minQuantityTickSzie.md) | Minimum market order quantity tick size |
diff --git a/.gitbook/calculations/minPriceTickSize.md b/.gitbook/calculations/minPriceTickSize.md
new file mode 100644
index 000000000..babc86b99
--- /dev/null
+++ b/.gitbook/calculations/minPriceTickSize.md
@@ -0,0 +1,47 @@
+# Market min price tick size
+
+The min market price tick size for an order price - if a market has an minPriceTickSick of `0.001` and order submission with the price of `0.0011` will be rejected.
+
+Note that calculating the formula for calculating a spot and quote market price tick size are different.
+
+### Spot market
+
+1. UI human readable to chain format:
+ Using INJ/USDT market which has 18 base decimals and 6 quote decimals as an example, here's how we convert the value to the chain format:
+
+```js
+const chainFormat = new BigNumberInBase(10)
+ .pow(quoteDecimal - baseDecimal)
+ .times(value)
+ .toFixed()
+```
+
+1. Chain format to UI human readable format:
+ Using INJ/USDT market which has 18 base decimals and 6 quote decimals as an example, here's how we convert the value to the UI human readable format:
+
+```js
+const humanReadableFormat = new BigNumber(value)
+ .shiftedBy(baseDecimals - quoteDecimals)
+ .toFixed()
+```
+
+### Derivative market
+
+1. UI human readable to chain format:
+ Using INJ/USDT perp market which has 6 quote decimals as an example, here's how we convert the value to the chain format:
+
+```js
+const chainFormat = new BigNumberInBase(10)
+ .pow(-quoteDecimal)
+ .times(value)
+ .toFixed()
+```
+
+1. Chain format to UI human readable format:
+ Using INJ/USDT perp market which has 6 quote decimals as an example, here's how we convert the value to the UI human readable format:
+
+```js
+const humanReadableFormat = new BigNumber(value)
+ .shiftedBy(-quoteDecimals)
+ .toFixed()
+```
diff --git a/.gitbook/calculations/minQuantityTickSize.md b/.gitbook/calculations/minQuantityTickSize.md
new file mode 100644
index 000000000..a5d16506a
--- /dev/null
+++ b/.gitbook/calculations/minQuantityTickSize.md
@@ -0,0 +1,23 @@
+# Market min quantity tick size
+
+The min market quantity tick size for an order price - if a market has an minQuantityTickSize of `0.001` and order submission with the quantity of `0.0011` will be rejected.
+
+Note that derivate markets shares the same format for minQuantityTickSize between UI and the chain, so no formatting is required.
+
+### Spot market
+
+1. UI human readable to chain format:
+ Using on a INJ/USDT market which has 18 base decimals and 6 quote decimals as an example, here's how we convert the value to the chain format:
+
+```js
+const chainFormat = new BigNumberInWei(value).toBase(baseDecimals)
+```
+
+1. Chain format to UI human readable format:
+ Using INJ/USDT market which has 18 base decimals and 6 quote decimals as an example, here's how we convert the value to the UI human readable format:
+
+```js
+const humanReadableFormat = new BigNumber(minQuantityTickSize)
+ .shiftedBy(-baseDecimals)
+ .toFixed()
+```
diff --git a/.gitbook/contracts.md b/.gitbook/contracts.md
deleted file mode 100644
index 39387df11..000000000
--- a/.gitbook/contracts.md
+++ /dev/null
@@ -1,6 +0,0 @@
-# Contracts
-
-### What is CosmWasm?[](https://docs.injective.network/develop/guides/cosmwasm-dapps/#what-is-cosmwasm)
-
-CosmWasm is a novel smart contracting platform built for the Cosmos ecosystem. You can learn more about CosmWasm [here](https://docs.cosmwasm.com/docs/), or see the [CosmWasm Book](https://book.cosmwasm.com/index.html) for a guide on creating CosmWasm smart contracts.
-
diff --git a/.gitbook/contracts/README.md b/.gitbook/contracts/README.md
index 6ab29fd7a..293ca8678 100644
--- a/.gitbook/contracts/README.md
+++ b/.gitbook/contracts/README.md
@@ -1,10 +1,10 @@
# Contracts
-### What is CosmWasm?[](https://docs.injective.network/develop/guides/cosmwasm-dapps/#what-is-cosmwasm)
+#### [What is CosmWasm?](./#what-is-cosmwasm-)[](https://docs.injective.network/develop/guides/cosmwasm-dapps/#what-is-cosmwasm)
CosmWasm is a novel smart contracting platform built for the Cosmos ecosystem. You can learn more about CosmWasm [here](https://docs.cosmwasm.com/docs/), or see the [CosmWasm Book](https://book.cosmwasm.com/index.html) for a guide on creating CosmWasm smart contracts.
-### Specific Cosmwasm Contracts
+#### Specific Cosmwasm Contracts
| Topic | Description |
| --------------------------------------------------- | ---------------------- |
diff --git a/.gitbook/contracts/injective-name-service.md b/.gitbook/contracts/injective-name-service.md
index 0e93a62ab..7d042afd4 100644
--- a/.gitbook/contracts/injective-name-service.md
+++ b/.gitbook/contracts/injective-name-service.md
@@ -1,14 +1,31 @@
# Injective Name Service
-Within this section we are going to have a look how to query the Injective name service contracts.
+Within this section, we will look at how to query the Injective name service contracts.
-## Querying
+## Abstraction Service
+
+You can use our `InjNameService` [abstraction](../../packages/sdk-ui-ts/src/services/nameservice/InjNameService.ts) to query the smart contracts with a single method call. Below this example, you can also find the raw implementation on how to query the smart contracts in case you need more flexibility.
+
+
import { getNetworkEndpoints, Network } from '@injectivelabs/network'
+import { InjNameService } from '@injectivelabs/sdk-ui-ts'
+
+const injNameService = new InjNameService(Network.Testnet)
+const name = 'ninja.inj'
+
+// Fetch the address for the particular name
+const addressForName = await injNameService.fetchInjAddress(name)
+
+// Fetch the name for the particular address
+const nameFromAddress = await injNameService.fetchInjName(addressForName)
+
+
+## Raw Smart Contract Querying
Example code snippets to resolve .inj domain name.
### Domain Resolution
-- Get resolver address
+* Get resolver address
```ts
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
@@ -41,7 +58,7 @@ const resolverAddress = InjNameServiceQueryTransformer.resolverAddressResponseTo
console.log(resolverAddress)
```
-- Get address for .inj domain name.
+* Get address for .inj domain name.
```ts
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
@@ -83,7 +100,7 @@ console.log(injectiveAddress)
### Reverse Resolution
-- Get primary name for injective address.
+* Get primary name for injective address.
```ts
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
diff --git a/.gitbook/core-modules/README.md b/.gitbook/core-modules/README.md
index 65f95d10a..f7968321b 100644
--- a/.gitbook/core-modules/README.md
+++ b/.gitbook/core-modules/README.md
@@ -10,6 +10,7 @@ Within this section, we are going to explore the core modules of the Injective c
| ------------------------------- | ------------------------------------------------ |
| [Auction](auction.md) | Use for the buy-back-and-burn on chain mechanism |
| [AuthZ](authz.md) | Used for granting account priveledges |
+| [Feegrant](feegrant.md) | Used for granting fee allowance priveledges |
| [Bank](bank.md) | Used for managing users assets (funds) |
| [Exchange](exchange.md) | Used for the exchange primitives |
| [Distribution](distribution.md) | Used for on-chain distribution/minting |
diff --git a/.gitbook/core-modules/auction.md b/.gitbook/core-modules/auction.md
index 550dfc240..8a6b14445 100644
--- a/.gitbook/core-modules/auction.md
+++ b/.gitbook/core-modules/auction.md
@@ -23,7 +23,7 @@ const auctionApi = new ChainGrpcAuctionApi(endpointsForNetwork.grpc);
const injectiveAddress = "inj1...";
/* format amount for bid, note that bid amount has to be higher than the current highest bid */
const amount = {
- denom: INJ,
+ denom: INJ_DENOM,
amount: new BigNumberInBase(1).toWei(),
};
@@ -38,20 +38,83 @@ const latestRound = uiLatestAuctionModuleState.auctionRound;
const msg = MsgBid.fromJSON({
amount,
injectiveAddress,
- round: latestRound,
+ round: latestRound
});
const privateKey = "0x...";
/* broadcast transaction */
const txHash = await new MsgBroadcasterWithPk({
- privateKey,
- chainId: ChainId.Mainnet,
- endpoints: endpointsForNetwork,
+network: Network.Mainnet,
+privateKey,
}).broadcast({
- msgs: msg,
- injectiveAddress,
-});
+msgs: msg
+})
+
console.log(txHash);
```
+
+### Burn Auction Deposit via MsgExternalTransfer
+
+If you would like to grow the burn auction's pool size, you can directly send funds to the Auction subaccount.
+
+Notes:
+ - You will need to send funds to the pool's subaccount `0x1111111111111111111111111111111111111111111111111111111111111111`.
+ - Be aware that any funds you send will be reflected in the next auction, not the current one.
+ - You cannot transfer from your default subaccountId since that balance is now associated with your Injective address in the bank module. Therefore, in order for `MsgExternalTransfer` to work, you will need to transfer from a non-default subaccountId.
+
+ How to find the subaccountId that you will be transferring from:
+ - you can query your existing subaccountIds via the [account portfolio api](../querying/querying-api/querying-indexer-portfolio.md).
+
+How to use funds that are currently associated with your Injective Address in bank module:
+ - If you have existing non-default subaccounts, you'll want to do a [MsgDeposit](./exchange.md#MsgDeposit) to one of your existing non-default subaccountIds and use that subaccountId as the `srcSubaccountId` below.
+ - If you don't have existing non-default subaccounts, you can do a [MsgDeposit](./exchange.md#MsgDeposit) to a new default subaccountId, which would be done via importing `getSubaccountId` from `sdk-ts` and setting the `subaccountId` field in [MsgDeposit](./exchange.md#MsgDeposit) to `getSubaccountId(injectiveAddress, 1)`.
+
+For more info, check out the [burn auction pool docs](https://docs.injective.network/develop/tech-concepts/auction_pool/).
+
+```ts
+import {
+ DenomClient,
+ MsgExternalTransfer,
+ MsgBroadcasterWithPk,
+} from '@injectivelabs/sdk-ts'
+import { BigNumberInBase } from '@injectivelabs/utils'
+import { Network } from '@injectivelabs/networks'
+
+const denomClient = new DenomClient(Network.Mainnet);
+
+const injectiveAddress = 'inj1...'
+const srcSubaccountId = '0x...'
+const POOL_SUBACCOUNT_ID = `0x1111111111111111111111111111111111111111111111111111111111111111`
+const USDT_TOKEN_SYMBOL='USDT'
+const tokenMeta = denomClient.getTokenMetaDataBySymbol(USDT_TOKEN_SYMBOL);
+const tokenDenom = `peggy${tokenMeta.erc20.address}`;
+
+/* format amount to add to the burn auction pool */
+const amount = {
+ denom: tokenDenom,
+ amount: new BigNumberInBase(1).toWei(tokenMeta.decimals).toFixed()
+}
+
+/* create message in proto format */
+const msg = MsgExternalTransfer.fromJSON({
+ amount,
+ srcSubaccountId,
+ injectiveAddress,
+ dstSubaccountId: POOL_SUBACCOUNT_ID
+})
+
+const privateKey = '0x...'
+
+/* broadcast transaction */
+const txHash = await new MsgBroadcasterWithPk({
+network: Network.Mainnet,
+privateKey
+}).broadcast({
+msgs: msg
+})
+
+
+console.log(txHash)
+```
diff --git a/.gitbook/core-modules/authz.md b/.gitbook/core-modules/authz.md
index 62cc30721..d589565fd 100644
--- a/.gitbook/core-modules/authz.md
+++ b/.gitbook/core-modules/authz.md
@@ -31,7 +31,7 @@ Per [cosmos sdk docs](https://docs.cosmos.network/main/modules/authz), "Authoriz
```ts
import { MsgGrant, MsgBroadcasterWithPk } from '@injectivelabs/sdk-ts'
-import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
+import { Network } from '@injectivelabs/networks'
const privateKeyOfGranter = '0x...'
const grantee = 'inj...'
@@ -46,11 +46,9 @@ const msg = MsgGrant.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey: privateKeyOfGranter,
- network: Network.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet)
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress: granter,
+ msgs: msg
})
console.log(txHash)
@@ -63,7 +61,7 @@ When a grantee wants to execute a transaction on behalf of a granter, they must
```ts
import { MsgExec, MsgSend, MsgBroadcasterWithPk } from '@injectivelabs/sdk-ts'
import { BigNumberInBase } from '@injectivelabs/utils'
-import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
+import { Network } from '@injectivelabs/networks'
const privateKeyOfGrantee = '0x...'
const grantee = 'inj...'
@@ -85,11 +83,9 @@ const msg = MsgExec.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey: privateKeyOfGrantee,
- network: Network.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet)
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress: grantee,
+ msgs: msg
})
console.log(txHash)
@@ -101,7 +97,7 @@ A grant can be removed with the MsgRevoke message.
```ts
import { MsgRevoke, MsgBroadcasterWithPk, getEthereumAddress } from '@injectivelabs/sdk-ts'
-import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
+import { Network } from '@injectivelabs/networks'
const privateKeyOfGranter = '0x...'
const grantee = 'inj...'
@@ -116,11 +112,9 @@ const msg = MsgRevoke.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey: privateKeyOfGranter,
- network: Network.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet)
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress: granter,
+ msgs: msg
})
console.log(txHash)
diff --git a/.gitbook/core-modules/bank.md b/.gitbook/core-modules/bank.md
index 16848b2e2..e3ccdaf91 100644
--- a/.gitbook/core-modules/bank.md
+++ b/.gitbook/core-modules/bank.md
@@ -15,8 +15,7 @@ This Message is used to send coins from one address to another.
```ts
import { MsgSend, MsgBroadcasterWithPk } from '@injectivelabs/sdk-ts'
import { BigNumberInBase } from '@injectivelabs/utils'
-import { ChainId } from '@injectivelabs/ts-types'
-import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
+import { Network } from '@injectivelabs/networks'
const privateKey = '0x...'
const injectiveAddress = 'inj1...'
@@ -27,16 +26,14 @@ const amount = {
const msg = MsgSend.fromJSON({
amount,
srcInjectiveAddress: injectiveAddress,
- dstInjectiveAddress: injectiveAddress,
+ dstInjectiveAddress: injectiveAddress
});
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet)
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
})
console.log(txHash)
diff --git a/.gitbook/core-modules/distribution.md b/.gitbook/core-modules/distribution.md
index f2f38b9d3..b9f60c029 100644
--- a/.gitbook/core-modules/distribution.md
+++ b/.gitbook/core-modules/distribution.md
@@ -13,10 +13,7 @@ import {
MsgBroadcasterWithPk,
MsgWithdrawDelegatorReward,
} from "@injectivelabs/sdk-ts";
-import { ChainId } from "@injectivelabs/ts-types";
-import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
-
-const endpointsForNetwork = getNetworkEndpoints(Network.Mainnet);
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const validatorAddress = "inj1...";
@@ -32,11 +29,9 @@ const privateKey = "0x...";
/* broadcast transaction */
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Mainnet,
- endpoints: endpointsForNetwork,
+ network: Network.Mainnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
@@ -51,10 +46,7 @@ import {
MsgBroadcasterWithPk,
MsgWithdrawValidatorCommission,
} from "@injectivelabs/sdk-ts";
-import { ChainId } from "@injectivelabs/ts-types";
-import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
-
-const endpointsForNetwork = getNetworkEndpoints(Network.Mainnet);
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const validatorAddress = "inj1...";
@@ -69,11 +61,9 @@ const privateKey = "0x...";
/* broadcast transaction */
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Mainnet,
- endpoints: endpointsForNetwork,
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
diff --git a/.gitbook/core-modules/exchange.md b/.gitbook/core-modules/exchange.md
index 45e53ea2d..552e813dc 100644
--- a/.gitbook/core-modules/exchange.md
+++ b/.gitbook/core-modules/exchange.md
@@ -15,7 +15,7 @@ This Message is used to send coins from the Bank module to a wallet's subaccount
```ts
import { MsgDeposit, MsgBroadcasterWithPk, getEthereumAddress } from '@injectivelabs/sdk-ts'
import { BigNumberInBase } from '@injectivelabs/utils'
-import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
+import { Network } from '@injectivelabs/networks'
const privateKey = '0x...'
const injectiveAddress = 'inj1...'
@@ -33,16 +33,14 @@ const subaccountId = ethereumAddress + suffix
const msg = MsgDeposit.fromJSON({
amount,
subaccountId,
- injectiveAddress,
+ injectiveAddress
});
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- network: Network.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet)
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
})
console.log(txHash)
@@ -55,7 +53,7 @@ This Message is used to send coins from the wallet's subaccount back to the user
```ts
import { MsgWithdraw, MsgBroadcasterWithPk, getEthereumAddress } from '@injectivelabs/sdk-ts'
import { BigNumberInBase } from '@injectivelabs/utils'
-import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
+import { Network } from '@injectivelabs/networks'
const privateKey = '0x...'
const injectiveAddress = 'inj1...'
@@ -73,16 +71,14 @@ const subaccountId = ethereumAddress + suffix
const msg = MsgWithdraw.fromJSON({
amount,
subaccountId,
- injectiveAddress,
+ injectiveAddress
});
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- network: Network.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet)
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
})
console.log(txHash)
@@ -97,10 +93,10 @@ import {
MsgCreateSpotLimitOrder,
MsgBroadcasterWithPk,
getEthereumAddress,
- getDerivativeMarketTensMultiplier
+ getSpotMarketTensMultiplier
} from '@injectivelabs/sdk-ts'
import { BigNumberInBase, spotPriceToChainPriceToFixed, spotQuantityToChainQuantityToFixed } from '@injectivelabs/utils'
-import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
+import { Network } from '@injectivelabs/networks'
const privateKey = '0x...'
const injectiveAddress = 'inj1...'
@@ -111,8 +107,8 @@ const market = {
quoteDecimals: 6,
minPriceTickSize: '', /* fetched from the chain */
minQuantityTickSize: '', /* fetched from the chain */
- priceTensMultiplier: '', /** can be fetched from getDerivativeMarketTensMultiplier */
- quantityTensMultiplier: '', /** can be fetched from getDerivativeMarketTensMultiplier */
+ priceTensMultiplier: '', /** can be fetched from getSpotMarketTensMultiplier */
+ quantityTensMultiplier: '', /** can be fetched from getSpotMarketTensMultiplier */
}
const order = {
@@ -141,16 +137,14 @@ const msg = MsgCreateSpotLimitOrder.fromJSON({
baseDecimals: market.baseDecimals
}),
marketId: market.marketId,
- feeRecipient: feeRecipient,
+ feeRecipient: feeRecipient
})
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- network: Network.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet)
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
})
console.log(txHash)
@@ -165,10 +159,10 @@ import {
MsgCreateSpotMarketOrder,
MsgBroadcasterWithPk,
getEthereumAddress,
- getDerivativeMarketTensMultiplier
+ getSpotMarketTensMultiplier
} from '@injectivelabs/sdk-ts'
import { BigNumberInBase, spotPriceToChainPriceToFixed, spotQuantityToChainQuantityToFixed } from '@injectivelabs/utils'
-import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
+import { Network } from '@injectivelabs/networks'
const privateKey = '0x...'
const injectiveAddress = 'inj1...'
@@ -179,8 +173,8 @@ const market = {
quoteDecimals: 6,
minPriceTickSize: '', /* fetched from the chain */
minQuantityTickSize: '', /* fetched from the chain */
- priceTensMultiplier: '', /** can be fetched from getDerivativeMarketTensMultiplier */
- quantityTensMultiplier: '', /** can be fetched from getDerivativeMarketTensMultiplier */
+ priceTensMultiplier: '', /** can be fetched from getSpotMarketTensMultiplier */
+ quantityTensMultiplier: '', /** can be fetched from getSpotMarketTensMultiplier */
}
const order = {
price: 10,
@@ -213,11 +207,9 @@ const msg = MsgCreateSpotMarketOrder.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- network: Network.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet)
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
})
console.log(txHash)
@@ -240,7 +232,7 @@ import {
derivativeQuantityToChainQuantityToFixed,
derivativeMarginToChainMarginToFixed
} from '@injectivelabs/utils'
-import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
+import { Network } from '@injectivelabs/networks'
const privateKey = '0x...'
const injectiveAddress = 'inj1...'
@@ -285,11 +277,9 @@ const msg = MsgCreateDerivativeLimitOrder.fromJSON(
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- network: Network.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet)
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
})
console.log(txHash)
@@ -312,7 +302,7 @@ import {
derivativeQuantityToChainQuantityToFixed,
derivativeMarginToChainMarginToFixed
} from '@injectivelabs/utils'
-import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
+import { Network } from '@injectivelabs/networks'
const privateKey = '0x...'
const injectiveAddress = 'inj1...'
@@ -362,11 +352,9 @@ const msg = MsgCreateDerivativeMarketOrder.fromJSON(
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- network: Network.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet)
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
})
console.log(txHash)
@@ -389,7 +377,7 @@ import {
derivativeQuantityToChainQuantityToFixed,
derivativeMarginToChainMarginToFixed
} from '@injectivelabs/utils'
-import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
+import { Network } from '@injectivelabs/networks'
const privateKey = '0x...'
const injectiveAddress = 'inj1...'
@@ -469,11 +457,9 @@ const msg = MsgBatchUpdateOrders.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- network: Network.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet)
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
})
console.log(txHash)
@@ -485,22 +471,19 @@ This Message is used to batch cancel spot orders on the chain
```ts
import { MsgBatchCancelSpotOrders, MsgBroadcasterWithPk } from '@injectivelabs/sdk-ts'
-import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
+import { Network } from '@injectivelabs/networks'
const privateKey = '0x...'
const injectiveAddress = 'inj1...'
-const orders = [
- {
+const orders = [{
marketId: '0x...',
subaccountId: '0x...',
orderHash: '0x...'
- },
- {
+ },{
marketId: '0x...',
subaccountId: '0x...',
orderHash: '0x...'
- }
-]
+}]
const messages = orders.map((order) =>
MsgBatchCancelSpotOrders.fromJSON({
@@ -517,11 +500,9 @@ const messages = orders.map((order) =>
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- network: Network.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet)
+ network: Network.Testnet
}).broadcast({
- msgs: messages,
- injectiveAddress,
+ msgs: messages
})
console.log(txHash)
@@ -533,22 +514,19 @@ This Message is used to batch cancel spot orders on the chain
```ts
import { MsgBatchCancelDerivativeOrders, MsgBroadcasterWithPk } from '@injectivelabs/sdk-ts'
-import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
+import { Network } from '@injectivelabs/networks'
const privateKey = '0x...'
const injectiveAddress = 'inj1...'
-const orders = [
- {
+const orders = [{
marketId: '0x...',
subaccountId: '0x...',
orderHash: '0x...'
- },
- {
+ },{
marketId: '0x...',
subaccountId: '0x...',
orderHash: '0x...'
- }
-]
+}]
const messages = orders.map((order) =>
MsgBatchCancelDerivativeOrders.fromJSON({
@@ -565,11 +543,9 @@ const messages = orders.map((order) =>
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- network: Network.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet)
+ network: Network.Testnet
}).broadcast({
- msgs: messages,
- injectiveAddress,
+ msgs: messages
})
console.log(txHash)
@@ -584,7 +560,7 @@ import {
MsgRewardsOptOut,
MsgBroadcasterWithPk,
} from '@injectivelabs/sdk-ts'
-import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
+import { Network } from '@injectivelabs/networks'
const privateKey = '0x...'
const injectiveAddress = 'inj...'
@@ -594,12 +570,72 @@ const msg = MsgRewardsOptOut.fromJSON(
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- network: Network.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet)
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
+ msgs: msg
+})
+
+console.log(txHash)
+```
+
+### MsgExternalTransfer
+
+This message is used to transfer balance from one subaccount to another subaccount.
+
+Note:
+
+* You cannot transfer from your default subaccountId since that balance is now associated with your Injective address in the bank module. Therefore, in order for `MsgExternalTransfer` to work, you will need to transfer from a non-default subaccountId.
+
+How to find the subaccountId that you will be transferring from:
+
+* you can query your existing subaccountIds via the [account portfolio api](../querying/querying-api/querying-indexer-portfolio.md).
+
+How to use funds that are currently associated with your Injective Address in bank module:
+
+* If you have existing non-default subaccounts, you'll want to do a [MsgDeposit](exchange.md#MsgDeposit) to one of your existing non-default subaccountIds and use that subaccountId as the `srcSubaccountId` below.
+* If you don't have existing non-default subaccounts, you can do a [MsgDeposit](exchange.md#MsgDeposit) to a new default subaccountId, which would be done via importing `getSubaccountId` from `sdk-ts` and setting the `subaccountId` field in [MsgDeposit](exchange.md#MsgDeposit) to `getSubaccountId(injectiveAddress, 1)`.
+
+```ts
+import {
+ DenomClient,
+ MsgExternalTransfer,
+ MsgBroadcasterWithPk,
+} from '@injectivelabs/sdk-ts'
+import { BigNumberInBase } from '@injectivelabs/utils'
+import { Network } from '@injectivelabs/networks'
+
+const denomClient = new DenomClient(Network.Testnet)
+
+const injectiveAddress = 'inj...'
+const srcSubaccountId = '0x...'
+const dstSubaccountId = `0x...`
+const INJ_TOKEN_SYMBOL = 'INJ'
+const tokenMeta = denomClient.getTokenMetaDataBySymbol(INJ_TOKEN_SYMBOL)
+const tokenDenom = `inj`
+
+/* format amount to add to the burn auction pool */
+const amount = {
+ denom: tokenDenom,
+ amount: new BigNumberInBase(1).toWei(tokenMeta.decimals).toFixed(),
+}
+
+/* create message in proto format */
+const msg = MsgExternalTransfer.fromJSON({
+ amount,
+ dstSubaccountId,
+ srcSubaccountId,
injectiveAddress,
})
+const privateKey = '0x...'
+
+/* broadcast transaction */
+const txHash = await new MsgBroadcasterWithPk({
+ network: Network.Testnet,
+ privateKey,
+}).broadcast({
+ msgs: msg
+})
+
console.log(txHash)
```
diff --git a/.gitbook/core-modules/feegrant.md b/.gitbook/core-modules/feegrant.md
new file mode 100644
index 000000000..c052621d6
--- /dev/null
+++ b/.gitbook/core-modules/feegrant.md
@@ -0,0 +1,75 @@
+# Fee Grant
+
+The `feegrant` module allows accounts (granters) to grant fee allowances to other accounts (grantees). This allows the grantee to use the granter's funds to pay for transaction fees.
+
+## Messages
+
+### MsgGrantAllowance
+
+A fee allowance grant is created using the `MsgGrantAllowance` message. If there is already a grant for the (granter, grantee) pair, then the new grant will overwrite the previous one.
+
+```ts
+import { MsgGrantAllowance, MsgBroadcasterWithPk } from '@injectivelabs/sdk-ts'
+import { Network } from '@injectivelabs/networks'
+
+
+const privateKeyOfGranter = '0x...'
+
+const date = new Date('2023-10-02T00:00:00Z')
+const expiration = date.getTime() / 1000
+const granter = 'inj...'
+const grantee = 'inj...'
+const allowance = {
+ spendLimit: [
+ {
+ denom: 'inj',
+ amount: '10000',
+ },
+ ],
+ expiration
+}
+
+const msg = MsgGrantAllowance.fromJSON({
+ granter,
+ grantee,
+ allowance,
+})
+
+const txHash = await new MsgBroadcasterWithPk({
+privateKey: privateKeyOfGranter,
+network: Network.Testnet,
+}).broadcast({
+msgs: msg,
+})
+
+console.log(txHash)
+
+```
+
+### MsgRevokeAllowance
+A grant can be removed using the MsgRevokeAllowance message. The grantee will no longer be able to use the granter's funds to pay for transaction fees.
+
+```ts
+import { MsgRevokeAllowance, MsgBroadcasterWithPk } from '@injectivelabs/sdk-ts'
+import { Network } from '@injectivelabs/networks'
+
+const privateKey= "0x..."
+const granteeAddress = 'inj...'
+const granterAddress = 'inj...'
+
+const params = {
+grantee: granteeAddress,
+granter: granterAddress,
+}
+
+const msg = MsgRevokeAllowance.fromJSON(params);
+
+const txHash = await new MsgBroadcasterWithPk({
+privateKey,
+network: Network.Testnet,
+}).broadcast({
+msgs: msg,
+})
+
+console.log(txHash)
+```
diff --git a/.gitbook/core-modules/governance.md b/.gitbook/core-modules/governance.md
index 81d7734bc..5f113fc08 100644
--- a/.gitbook/core-modules/governance.md
+++ b/.gitbook/core-modules/governance.md
@@ -18,8 +18,7 @@ import {
MsgBroadcasterWithPk,
} from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
-import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
-import { ChainId } from "@injectivelabs/ts-types";
+import { Network } from "@injectivelabs/networks";
const INJ_DENOM = 'inj'
const amount = new BigNumberInBase(1).toWei().toFixed()
@@ -39,11 +38,9 @@ const message = MsgGovDeposit.fromJSON({
/* broadcast transaction */
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: message,
- injectiveAddress,
+ msgs: message
});
```
@@ -56,8 +53,7 @@ import {
MsgVote,
MsgBroadcasterWithPk
} from "@injectivelabs/sdk-ts";
-import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
-import { ChainId } from "@injectivelabs/ts-types";
+import { Network } from "@injectivelabs/networks";
import { VoteOption } from '@injectivelabs/sdk-ts';
const injectiveAddress = "inj...";
@@ -73,11 +69,9 @@ const message = MsgVote.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: message,
- injectiveAddress,
+ msgs: message
});
```
@@ -90,8 +84,7 @@ import {
MsgSubmitTextProposal,
MsgBroadcasterWithPk
} from "@injectivelabs/sdk-ts";
-import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
-import { ChainId } from "@injectivelabs/ts-types";
+import { Network } from "@injectivelabs/networks";
import { BigNumberInBase } from "@injectivelabs/utils";
const injectiveAddress = "inj...";
@@ -111,11 +104,9 @@ const message = MsgSubmitTextProposal.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: message,
- injectiveAddress,
+ msgs: message
});
```
@@ -125,13 +116,12 @@ This message allows you to propose a new spot market. Ensure that the ticker is
```ts
import {
- DenomClient,
+ DenomClientAsync,
MsgBroadcasterWithPk,
MsgSubmitProposalSpotMarketLaunch
} from "@injectivelabs/sdk-ts";
import { BigNumberInBase, BigNumberInWei } from "@injectivelabs/utils";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
-import { ChainId } from "@injectivelabs/ts-types";
const injectiveAddress = "inj...";
const privateKey = "0x...";
@@ -150,7 +140,8 @@ const market = {
minQuantityTickSize: '0.001'
}
-const denomClient = new DenomClient(
+const denomClient = new DenomClientAsync
+(
NETWORK.Testnet,
{ endpoints: getNetworkEndpoints(Network.Testnet) }
)
@@ -191,11 +182,9 @@ const message = MsgSubmitProposalSpotMarketLaunch.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: message,
- injectiveAddress
+ msgs: message
});
```
@@ -205,13 +194,12 @@ This message allows you to propose a new perpetual market. perpetual futures con
```ts
import {
- DenomClient,
+ DenomClientAsync,
MsgBroadcasterWithPk,
MsgSubmitProposalPerpetualMarketLaunch
} from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
-import { ChainId } from "@injectivelabs/ts-types";
const injectiveAddress = "inj...";
const privateKey = "0x...";
@@ -235,7 +223,7 @@ const market = {
minQuantityTickSize: '0.01'
}
-const denomClient = new DenomClient(
+const denomClient = new DenomClientAsync(
NETWORK.Testnet,
{ endpoints: getNetworkEndpoints(Network.Testnet) }
)
@@ -266,11 +254,9 @@ const message = MsgSubmitProposalPerpetualMarketLaunch.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: message,
- injectiveAddress
+ msgs: message
});
```
@@ -280,13 +266,12 @@ An expiry futures contract is an agreement between two counterparties to buy and
```ts
import {
- DenomClient,
+ DenomClientAsync,
MsgBroadcasterWithPk,
MsgSubmitProposalExpiryFuturesMarketLaunch
} from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
-import { ChainId } from "@injectivelabs/ts-types";
const injectiveAddress = "inj...";
const privateKey = "0x...";
@@ -311,7 +296,7 @@ const market = {
minQuantityTickSize: '0.01'
}
-const denomClient = new DenomClient(
+const denomClient = new DenomClientAsync(
NETWORK.Testnet,
{ endpoints: getNetworkEndpoints(Network.Testnet) }
)
@@ -342,11 +327,9 @@ const message = MsgSubmitProposalExpiryFuturesMarketLaunch.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: message,
- injectiveAddress
+ msgs: message
});
```
@@ -360,8 +343,7 @@ import {
MsgSubmitProposalSpotMarketParamUpdate
} from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
-import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
-import { ChainId } from "@injectivelabs/ts-types";
+import { Network } from "@injectivelabs/networks";
import { MarketStatusMap } from '@injectivelabs/chain-api';
const injectiveAddress = "inj...";
@@ -392,10 +374,8 @@ const message = MsgSubmitProposalSpotMarketParamUpdate.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: message,
- injectiveAddress
+ msgs: message
});
```
diff --git a/.gitbook/core-modules/ibc.md b/.gitbook/core-modules/ibc.md
index 800353a86..1ab09d1de 100644
--- a/.gitbook/core-modules/ibc.md
+++ b/.gitbook/core-modules/ibc.md
@@ -17,9 +17,9 @@ import {
MsgTransfer,
} from '@injectivelabs/sdk-ts'
import {
- cosmosNativeDenomsFromChainId,
TokenService,
UiBankTransformer,
+ cosmosChainTokenMetaMap,
} from '@injectivelabs/sdk-ui-ts'
import { BigNumberInBase } from '@injectivelabs/utils'
import { ChainId, CosmosChainId } from '@injectivelabs/ts-types'
@@ -46,7 +46,7 @@ const ibcSupplyWithToken = (await tokenService.getIbcSupplyWithToken(
/* get metadata for canonical denoms available for transfer between chains */
const cosmosHubBaseDenom = 'uatom'
-const tokenMeta = cosmosNativeDenomsFromChainId[destinationChainId]
+const tokenMeta = cosmosChainTokenMetaMap[destinationChainId]
const atomToken = (
Array.isArray(tokenMeta)
? tokenMeta.find((token) => token.denom === cosmosHubBaseDenom)
@@ -105,11 +105,9 @@ const privateKey = '0x...'
/* broadcast transaction */
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Mainnet,
- endpoints: endpointsForNetwork,
+ network: Network.Mainnet,
}).broadcast({
msgs: msg,
- injectiveAddress,
})
console.log(txHash)
diff --git a/.gitbook/core-modules/insurance.md b/.gitbook/core-modules/insurance.md
index 0abca6db8..478622cf3 100644
--- a/.gitbook/core-modules/insurance.md
+++ b/.gitbook/core-modules/insurance.md
@@ -16,8 +16,7 @@ import {
MsgBroadcasterWithPk,
} from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
-import { ChainId } from "@injectivelabs/ts-types";
-import { Network, getNetworkEndpoints } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
@@ -41,11 +40,9 @@ const msg = MsgCreateInsuranceFund.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
@@ -61,8 +58,7 @@ import {
MsgBroadcasterWithPk,
} from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
-import { ChainId } from "@injectivelabs/ts-types";
-import { Network, getNetworkEndpoints } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
@@ -81,11 +77,9 @@ const msg = MsgRequestRedemption.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
@@ -98,8 +92,7 @@ This Message is used to underwrite to an insurance fund.
```ts
import { MsgUnderwrite, MsgBroadcasterWithPk } from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
-import { ChainId } from "@injectivelabs/ts-types";
-import { Network, getNetworkEndpoints } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
@@ -118,11 +111,9 @@ const msg = MsgUnderwrite.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
diff --git a/.gitbook/core-modules/peggy.md b/.gitbook/core-modules/peggy.md
index 06163bca5..6004d60a4 100644
--- a/.gitbook/core-modules/peggy.md
+++ b/.gitbook/core-modules/peggy.md
@@ -10,7 +10,7 @@ Note that a $10 USD bridge fee will be charged for this transaction to cover for
```ts
import {
- DenomClient,
+ DenomClientAsync,
MsgSendToEth,
MsgBroadcasterWithPk,
} from "@injectivelabs/sdk-ts";
@@ -27,7 +27,7 @@ const tokenService = new TokenService({
const ETH_BRIDGE_FEE_IN_USD = 10;
const endpointsForNetwork = getNetworkEndpoints(Network.Mainnet);
-const denomClient = new DenomClient(Network.Mainnet, {
+const denomClient = new DenomClientAsync(Network.Mainnet, {
endpoints: endpointsForNetwork,
});
@@ -39,13 +39,15 @@ const injectiveAddress = "inj1...";
const destinationAddress = "0x..."; // ethereum address
const tokenDenom = `peggy${tokenMeta.erc20.address}`;
-if (!tokenDenom) {
+if (!tokenMeta) {
return;
}
-const tokenUsdPrice = tokenService.fetchUsdTokenPrice(tokenDenom.coinGeckoId);
+const tokenUsdPrice = tokenService.fetchUsdTokenPrice(tokenMeta
+.coinGeckoId);
const amountToFixed = new BigNumberInBase(amount)
- .toWei(tokenDenom.decimals)
+ .toWei(tokenMeta
+.decimals)
.toFixed();
const bridgeFeeInToken = new BigNumberInBase(ETH_BRIDGE_FEE_IN_USD)
.dividedBy(tokenUsdPrice)
@@ -66,10 +68,8 @@ const msg = MsgSendToEth.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Mainnet,
- endpoints: endpointsForNetwork,
+ network: Network.Mainnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
```
diff --git a/.gitbook/core-modules/staking.md b/.gitbook/core-modules/staking.md
index e8613638c..b9137ec3d 100644
--- a/.gitbook/core-modules/staking.md
+++ b/.gitbook/core-modules/staking.md
@@ -16,8 +16,7 @@ import {
MsgBroadcasterWithPk
} from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
-import { ChainId } from "@injectivelabs/ts-types";
-import { Network, getNetworkEndpoints } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
@@ -38,11 +37,9 @@ const msg = MsgBeginRedelegate.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
@@ -55,8 +52,7 @@ This Message is used to Delegate INJ to a validator.
```ts
import { MsgDelegate, MsgBroadcasterWithPk } from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
-import { ChainId } from "@injectivelabs/ts-types";
-import { Network, getNetworkEndpoints } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
@@ -74,11 +70,9 @@ const msg = MsgDelegate.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
@@ -91,8 +85,7 @@ This Message is used to Delegate INJ to a validator.
```ts
import { MsgUndelegate, MsgBroadcasterWithPk } from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
-import { ChainId } from "@injectivelabs/ts-types";
-import { Network, getNetworkEndpoints } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
@@ -110,11 +103,9 @@ const msg = MsgUndelegate.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
diff --git a/.gitbook/core-modules/token-factory.md b/.gitbook/core-modules/token-factory.md
index 636a2dc69..67858b309 100644
--- a/.gitbook/core-modules/token-factory.md
+++ b/.gitbook/core-modules/token-factory.md
@@ -19,8 +19,7 @@ import {
MsgCreateDenom,
} from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
-import { ChainId } from "@injectivelabs/ts-types";
-import { Network, getNetworkEndpoints } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
@@ -33,11 +32,9 @@ const msg = MsgCreateDenom.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
@@ -52,8 +49,7 @@ import {
MsgMint,
} from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
-import { ChainId } from "@injectivelabs/ts-types";
-import { Network, getNetworkEndpoints } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
@@ -70,11 +66,9 @@ const msg = MsgMint.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
@@ -89,8 +83,7 @@ import {
MsgBurn,
} from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
-import { ChainId } from "@injectivelabs/ts-types";
-import { Network, getNetworkEndpoints } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
@@ -107,11 +100,9 @@ const msg = MsgBurn.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
@@ -126,8 +117,7 @@ import {
MsgSetDenomMetadata,
} from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
-import { ChainId } from "@injectivelabs/ts-types";
-import { Network, getNetworkEndpoints } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
@@ -155,7 +145,7 @@ const denomUnitsIfTokenHas6Decimals = [
},
]
const displayIfTokenHas6Decimals = subdenom
-const displayIfTokenHas0Decimals =
+const displayIfTokenHas0Decimals =
const msg = MsgSetDenomMetadata.fromJSON({
sender: injectiveAddress,
@@ -172,11 +162,9 @@ const msg = MsgSetDenomMetadata.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
@@ -191,8 +179,7 @@ import {
MsgSetDenomMetadata,
} from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
-import { ChainId } from "@injectivelabs/ts-types";
-import { Network, getNetworkEndpoints } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
@@ -237,11 +224,9 @@ const msgSetDenomMetadata = MsgSetDenomMetadata.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: [msgCreateDenom, msgMint, msgSetDenomMetadata],
- injectiveAddress,
+ msgs: [msgCreateDenom, msgMint, msgSetDenomMetadata]
});
console.log(txHash);
diff --git a/.gitbook/core-modules/tokenfactory.md b/.gitbook/core-modules/tokenfactory.md
index 684f44376..0b77e733f 100644
--- a/.gitbook/core-modules/tokenfactory.md
+++ b/.gitbook/core-modules/tokenfactory.md
@@ -17,8 +17,7 @@ import {
MsgCreateDenom,
} from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
-import { ChainId } from "@injectivelabs/ts-types";
-import { Network, getNetworkEndpoints } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
@@ -31,11 +30,9 @@ const msg = MsgCreateDenom.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
@@ -50,8 +47,7 @@ import {
MsgMint,
} from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
-import { ChainId } from "@injectivelabs/ts-types";
-import { Network, getNetworkEndpoints } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
@@ -68,11 +64,9 @@ const msg = MsgMint.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
msgs: msg,
- injectiveAddress,
});
console.log(txHash);
@@ -87,8 +81,7 @@ import {
MsgBurn,
} from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
-import { ChainId } from "@injectivelabs/ts-types";
-import { Network, getNetworkEndpoints } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
@@ -105,11 +98,9 @@ const msg = MsgBurn.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
@@ -125,8 +116,7 @@ import {
MsgSetDenomMetadata,
} from "@injectivelabs/sdk-ts";
import { BigNumberInBase } from "@injectivelabs/utils";
-import { ChainId } from "@injectivelabs/ts-types";
-import { Network, getNetworkEndpoints } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
@@ -169,11 +159,9 @@ const msg = MsgSetDenomMetadata.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
diff --git a/.gitbook/core-modules/wasm.md b/.gitbook/core-modules/wasm.md
index ae2b4d9f2..1f085d820 100644
--- a/.gitbook/core-modules/wasm.md
+++ b/.gitbook/core-modules/wasm.md
@@ -11,8 +11,7 @@ import {
MsgExecuteContract,
MsgBroadcasterWithPk,
} from "@injectivelabs/sdk-ts";
-import { ChainId } from "@injectivelabs/ts-types";
-import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const recipientAddress = "inj2...";
@@ -32,11 +31,9 @@ const msg = MsgExecuteContract.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Mainnet,
- endpoints: endpointsForNetwork,
+ network: Network.Mainnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
@@ -44,9 +41,9 @@ console.log(txHash);
### MsgExecuteContract (funds example)
-In some scenario, depending on the smart contract's function we have to transfer tokens to the smart contract, following cosmwasm convention we use the funds field to transfer tokens to the smart contract from the user's bank module.
+In some scenarios, depending on the smart contract's function we have to transfer tokens to the smart contract, following cosmwasm convention, we use the funds field to transfer tokens to the smart contract from the user's bank module.
-Below is an example of how we can send the MsgExecuteContract using an `test` contract function.
+Below is an example of how we can send the `MsgExecuteContract` using an `test` contract function.
```ts
import {
@@ -54,8 +51,7 @@ import {
MsgBroadcasterWithPk,
} from "@injectivelabs/sdk-ts";
import { INJ_DENOM } from "@injectivelabs/sdk-ui-ts";
-import { ChainId } from "@injectivelabs/ts-types";
-import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const contractAddress = "cw...";
@@ -76,11 +72,9 @@ const msg = MsgExecuteContract.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Mainnet,
- endpoints: endpointsForNetwork,
+ network: Network.Mainnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
@@ -88,30 +82,11 @@ console.log(txHash);
### MsgExecuteContractCompact
-There are some compatibility issue parsing the funds array in the previous example with EIP712, hence we introduced MsgExecuteContractCompact which converts the funds into a string
+There are some compatibility issues parsing the `funds` array and `msgs` object in the previous example with EIP712. Since `MsgExecuteContract` can't be properly converted to EIP712 and then signed by Ethereum wallets, we introduced `MsgExecuteContractCompact` which is fully compatible with EIP712.
-An array of funds:
+_**Note:**_ _`MsgExecuteContract` and `MsgExecuteContractCompat` underlying messages are the same. `MsgExecuteContractCompat` is just EIP712 compatible._
-```ts
-const funds = [
- {
- denom: denom1,
- amount: new BigNumberInBase(1).toWei().toFixed(),
- },
- {
- denom: denom2,
- amount: new BigNumberInBase(1).toWei().toFixed(),
- },
-];
-```
-
-will be presented as a string like this:
-
-```ts
-const funds = "100000000000000000 denom1, 100000000000000000 denom2";
-```
-
-Below is an example of how we can send the MsgExecuteContractCompact using an `test` contract function.
+Below is an example of how we can send the `MsgExecuteContractCompact` using an `test` contract function.
```ts
import {
@@ -119,8 +94,7 @@ import {
MsgExecuteContractCompact,
} from "@injectivelabs/sdk-ts";
import { INJ_DENOM } from "@injectivelabs/sdk-ui-ts";
-import { ChainId } from "@injectivelabs/ts-types";
-import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
+import { Network } from "@injectivelabs/networks";
const injectiveAddress = "inj1...";
const contractAddress = "cw...";
@@ -141,11 +115,9 @@ const msg = MsgExecuteContractCompact.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Mainnet,
- endpoints: endpointsForNetwork,
+ network: Network.Mainnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
});
console.log(txHash);
diff --git a/.gitbook/readme/token-metadata/creating-tokens.md b/.gitbook/readme/token-metadata/creating-tokens.md
index a74e9c2aa..016ff789a 100644
--- a/.gitbook/readme/token-metadata/creating-tokens.md
+++ b/.gitbook/readme/token-metadata/creating-tokens.md
@@ -10,4 +10,4 @@ A single account can create multiple denoms, by providing a unique subdenom for
* Change the admin. In the future, more admin capabilities may be added. Admins can choose to share admin privileges with other accounts using the authz module. The ChangeAdmin functionality allows changing the master admin account, or even setting it to "", meaning no account has admin privileges over the asset.
* Set their token metadata on chain
-To start creating your denoms, head to our [TokenFactory Core Module page](../../core-modules/token-factory.md) to see examples.
+To start creating your denoms, head to our [TokenFactory Core Module page ](../../core-modules/token-factory.md)to see examples.
diff --git a/.gitbook/transactions/ethereum.md b/.gitbook/transactions/ethereum.md
index 843cc3e04..fa415f959 100644
--- a/.gitbook/transactions/ethereum.md
+++ b/.gitbook/transactions/ethereum.md
@@ -9,7 +9,7 @@ First of, we need to prepare the transaction for signing. To use Ethereum native
Using our custom abstraction for the Messages which allows the developer to get EIP712 TypedData straight from the proto file of the particular message.
```ts
-import {
+import {
MsgSend,
ChainRestAuthApi,
ChainRestTendermintApi,
@@ -17,22 +17,24 @@ import {
DEFAULT_STD_FEE,
getEip712TypedData,
} from '@injectivelabs/sdk-ts'
-import { DEFAULT_STD_FEE, DEFAULT_BLOCK_TIMEOUT_HEIGHT } from '@injectivelabs/utils'
+import {
+ DEFAULT_STD_FEE,
+ DEFAULT_BLOCK_TIMEOUT_HEIGHT,
+} from '@injectivelabs/utils'
import { ChainId } from '@injectivelabs/ts-types'
import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
const injectiveAddress = 'inj1'
const chainId = 'injective-1' /* ChainId.Mainnet */
-const restEndpoint = 'https://lcd.injective.network' /* getNetworkEndpoints(Network.Mainnet).rest */
+const restEndpoint =
+ 'https://lcd.injective.network' /* getNetworkEndpoints(Network.Mainnet).rest */
const amount = {
amount: new BigNumberInBase(0.01).toWei().toFixed(),
- denom: "inj",
-};
+ denom: 'inj',
+}
/** Account Details **/
-const chainRestAuthApi = new ChainRestAuthApi(
- restEndpoint,
-)
+const chainRestAuthApi = new ChainRestAuthApi(restEndpoint)
const accountDetailsResponse = await chainRestAuthApi.fetchAccount(
injectiveAddress,
)
@@ -40,9 +42,7 @@ const baseAccount = BaseAccount.fromRestApi(accountDetailsResponse)
const accountDetails = baseAccount.toAccountDetails()
/** Block Details */
-const chainRestTendermintApi = new ChainRestTendermintApi(
- restEndpoint,
-)
+const chainRestTendermintApi = new ChainRestTendermintApi(restEndpoint)
const latestBlock = await chainRestTendermintApi.fetchLatestBlock()
const latestHeight = latestBlock.header.height
const timeoutHeight = new BigNumberInBase(latestHeight).plus(
@@ -54,7 +54,7 @@ const msg = MsgSend.fromJSON({
amount,
srcInjectiveAddress: injectiveAddress,
dstInjectiveAddress: injectiveAddress,
-});
+})
/** EIP712 for signing on Ethereum wallets */
const eip712TypedData = getEip712TypedData({
@@ -77,14 +77,14 @@ Once we have prepared the EIP712 typed data, we proceed to signing.
/** Use your preferred approach to sign EIP712 TypedData, example with Metamask */
const signature = await window.ethereum.request({
method: 'eth_signTypedData_v4',
- params: [ethereumAddress, JSON.stringify(eip712TypedData /* from previous step */)],
+ params: [
+ ethereumAddress,
+ JSON.stringify(eip712TypedData /* from previous step */),
+ ],
})
/** Get Public Key of the signer */
-const publicKeyHex = recoverTypedSignaturePubKey(
- eip712TypedData,
- signature,
-)
+const publicKeyHex = recoverTypedSignaturePubKey(eip712TypedData, signature)
const publicKeyBase64 = hexToBase64(publicKeyHex)
```
@@ -97,7 +97,11 @@ Once we have the signature ready, we need to broadcast the transaction to the In
```ts
import { ChainId } from '@injectivelabs/ts-types'
import { createTransaction, TxRestClient } from '@injectivelabs/sdk-ts'
-import { SIGN_AMINO, Network, getNetworkEndpoints } from '@injectivelabs/networks'
+import {
+ SIGN_AMINO,
+ Network,
+ getNetworkEndpoints,
+} from '@injectivelabs/networks'
const { txRaw } = createTransaction({
message: msgs,
@@ -119,19 +123,20 @@ const txRawEip712 = createTxRawEIP712(txRaw, web3Extension)
txRawEip712.signatures = [signatureBuff /* From previous step */]
/** Broadcast the Transaction */
-const restEndpoint = 'https://lcd.injective.network' /* getNetworkEndpoints(Network.Mainnet).rest */
+const restEndpoint =
+ 'https://lcd.injective.network' /* getNetworkEndpoints(Network.Mainnet).rest */
const txRestClient = new TxRestClient(restEndpoint)
const txHash = await txRestClient.broadcast(txRawEip712)
-/**
- * Once we get the txHash, because we use the Sync mode we
- * are not sure that the transaction is included in the block,
- * it can happen that it's still in the mempool so we need to query
+/**
+ * Once we get the txHash, because we use the Sync mode we
+ * are not sure that the transaction is included in the block,
+ * it can happen that it's still in the mempool so we need to query
* the chain to see when the transaction will be included
*/
- /** This will poll querying the transaction and await for it's inclusion in the block */
+/** This will poll querying the transaction and await for it's inclusion in the block */
const response = await txRestClient.fetchTxPoll(txHash)
```
@@ -140,7 +145,7 @@ const response = await txRestClient.fetchTxPoll(txHash)
Let's have a look at the whole flow (using Metamask as a signing wallet)
```ts
-import {
+import {
MsgSend,
ChainRestAuthApi,
ChainRestTendermintApi,
@@ -148,22 +153,24 @@ import {
DEFAULT_STD_FEE,
getEip712TypedData,
} from '@injectivelabs/sdk-ts'
-import { DEFAULT_STD_FEE, DEFAULT_BLOCK_TIMEOUT_HEIGHT } from '@injectivelabs/utils'
+import {
+ DEFAULT_STD_FEE,
+ DEFAULT_BLOCK_TIMEOUT_HEIGHT,
+} from '@injectivelabs/utils'
import { ChainId } from '@injectivelabs/ts-types'
import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
const injectiveAddress = 'inj1'
const chainId = 'injective-1' /* ChainId.Mainnet */
-const restEndpoint = 'https://lcd.injective.network' /* getNetworkEndpoints(Network.Mainnet).rest */
+const restEndpoint =
+ 'https://lcd.injective.network' /* getNetworkEndpoints(Network.Mainnet).rest */
const amount = {
amount: new BigNumberInBase(0.01).toWei().toFixed(),
- denom: "inj",
-};
+ denom: 'inj',
+}
/** Account Details **/
-const chainRestAuthApi = new ChainRestAuthApi(
- restEndpoint,
-)
+const chainRestAuthApi = new ChainRestAuthApi(restEndpoint)
const accountDetailsResponse = await chainRestAuthApi.fetchAccount(
injectiveAddress,
)
@@ -171,9 +178,7 @@ const baseAccount = BaseAccount.fromRestApi(accountDetailsResponse)
const accountDetails = baseAccount.toAccountDetails()
/** Block Details */
-const chainRestTendermintApi = new ChainRestTendermintApi(
- restEndpoint,
-)
+const chainRestTendermintApi = new ChainRestTendermintApi(restEndpoint)
const latestBlock = await chainRestTendermintApi.fetchLatestBlock()
const latestHeight = latestBlock.header.height
const timeoutHeight = new BigNumberInBase(latestHeight).plus(
@@ -185,7 +190,7 @@ const msg = MsgSend.fromJSON({
amount,
srcInjectiveAddress: injectiveAddress,
dstInjectiveAddress: injectiveAddress,
-});
+})
/** EIP712 for signing on Ethereum wallets */
const eip712TypedData = getEip712TypedData({
@@ -206,10 +211,7 @@ const signature = await window.ethereum.request({
})
/** Get Public Key of the signer */
-const publicKeyHex = recoverTypedSignaturePubKey(
- eip712TypedData,
- signature,
-)
+const publicKeyHex = recoverTypedSignaturePubKey(eip712TypedData, signature)
const publicKeyBase64 = hexToBase64(publicKeyHex)
const { txRaw } = createTransaction({
@@ -240,8 +242,4 @@ const response = await txRestClient.fetchTxPoll(txHash)
### Example with WalletStrategy (Prepare + Sign + Broadcast)
-🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧
-
-This part is currently under work in progress.
-
-🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧
+Example can be found [here](https://github.com/InjectiveLabs/injective-ts/blob/862e7c30d96120947b056abffbd01b4f378984a1/packages/wallet-ts/src/broadcaster/MsgBroadcaster.ts#L166-L248).
diff --git a/.gitbook/transactions/private-key.md b/.gitbook/transactions/private-key.md
index bca0508fa..888432219 100644
--- a/.gitbook/transactions/private-key.md
+++ b/.gitbook/transactions/private-key.md
@@ -225,8 +225,7 @@ You can use the `MsgBroadcasterWithPk` class from the `@injectivelabs/sdk-ts` pa
```ts
import { MsgSend, MsgBroadcasterWithPk } from '@injectivelabs/sdk-ts'
import { BigNumberInBase } from '@injectivelabs/utils'
-import { ChainId } from '@injectivelabs/ts-types'
-import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
+import { Network } from '@injectivelabs/networks'
const privateKey = '0x...'
const injectiveAddress = 'inj1...'
@@ -242,11 +241,9 @@ const msg = MsgSend.fromJSON({
const txHash = await new MsgBroadcasterWithPk({
privateKey,
- chainId: ChainId.Testnet,
- endpoints: getNetworkEndpoints(Network.Testnet),
+ network: Network.Testnet
}).broadcast({
- msgs: msg,
- injectiveAddress,
+ msgs: msg
})
console.log(txHash)
diff --git a/.gitbook/transactions/transactions-cosmos.md b/.gitbook/transactions/transactions-cosmos.md
index 3846e6124..f5e96c69c 100644
--- a/.gitbook/transactions/transactions-cosmos.md
+++ b/.gitbook/transactions/transactions-cosmos.md
@@ -10,31 +10,35 @@ At this point you **can't** use some online abstractions that provide a quick wa
To resolve this, we have provided functions which can prepare the `txRaw` transaction within out `@injectivelabs/sdk-ts` package. `txRaw` is the transaction interface used in Cosmos that contains details about the transaction and the signer itself.
+Getting a private key from cosmos wallets is usually done by taking the current key for the chainId and accessing the pubKey from there (ex: `const key = await window.keplr.getKey(chainId)` => `const pubKey = key.publicKey`).
+
```ts
-import {
+import {
MsgSend,
- ChainRestAuthApi,
- ChainRestTendermintApi,
BaseAccount,
DEFAULT_STD_FEE,
+ ChainRestAuthApi,
createTransaction,
+ ChainRestTendermintApi,
} from '@injectivelabs/sdk-ts'
-import { DEFAULT_STD_FEE, DEFAULT_BLOCK_TIMEOUT_HEIGHT } from '@injectivelabs/utils'
+import {
+ DEFAULT_STD_FEE,
+ DEFAULT_BLOCK_TIMEOUT_HEIGHT,
+} from '@injectivelabs/utils'
import { ChainId } from '@injectivelabs/ts-types'
import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
const injectiveAddress = 'inj1'
const chainId = 'injective-1' /* ChainId.Mainnet */
-const restEndpoint = 'https://lcd.injective.network' /* getNetworkEndpoints(Network.Mainnet).rest */
+const restEndpoint =
+ 'https://lcd.injective.network' /* getNetworkEndpoints(Network.Mainnet).rest */
const amount = {
amount: new BigNumberInBase(0.01).toWei().toFixed(),
- denom: "inj",
-};
+ denom: 'inj',
+}
/** Account Details **/
-const chainRestAuthApi = new ChainRestAuthApi(
- restEndpoint,
-)
+const chainRestAuthApi = new ChainRestAuthApi(restEndpoint)
const accountDetailsResponse = await chainRestAuthApi.fetchAccount(
injectiveAddress,
)
@@ -42,9 +46,7 @@ const baseAccount = BaseAccount.fromRestApi(accountDetailsResponse)
const accountDetails = baseAccount.toAccountDetails()
/** Block Details */
-const chainRestTendermintApi = new ChainRestTendermintApi(
- restEndpoint,
-)
+const chainRestTendermintApi = new ChainRestTendermintApi(restEndpoint)
const latestBlock = await chainRestTendermintApi.fetchLatestBlock()
const latestHeight = latestBlock.header.height
const timeoutHeight = new BigNumberInBase(latestHeight).plus(
@@ -56,7 +58,7 @@ const msg = MsgSend.fromJSON({
amount,
srcInjectiveAddress: injectiveAddress,
dstInjectiveAddress: injectiveAddress,
-});
+})
/** Get the PubKey of the Signer from the Wallet/Private Key */
const pubKey = await getPubKey()
@@ -82,7 +84,7 @@ import { ChainId } from '@injectivelabs/ts-types'
const getKeplr = async (chainId) => {
await window.keplr.enable(chainId);
-
+
const offlineSigner = window.keplr.getOfflineSigner(chainId);
const accounts = await offlineSigner.getAccounts();
const key = await window.keplr.getKey(chainId);
@@ -106,22 +108,22 @@ Once we have the signature ready, we need to broadcast the transaction to the In
```ts
import { ChainId } from '@injectivelabs/ts-types'
-import { getTxRawFromTxRawOrDirectSignResponse, TxRestClient } from '@injectivelabs/sdk-ts'
+import { CosmosTxV1Beta1Tx, getTxRawFromTxRawOrDirectSignResponse, TxRestClient } from '@injectivelabs/sdk-ts'
import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
-/**
- * IMPORTANT NOTE:
- * If we use Keplr/Leap wallets
- * after signing the transaction we get a `directSignResponse`,
+/**
+ * IMPORTANT NOTE:
+ * If we use Keplr/Leap wallets
+ * after signing the transaction we get a `directSignResponse`,
* and instead of adding the signature to the `txRaw` we create
- * using the `createTransaction` function we need to append the
- * signature from the `directSignResponse` to the transaction that
- * got actually signed (i.e `directSignResponse.signed`) and
+ * using the `createTransaction` function we need to append the
+ * signature from the `directSignResponse` to the transaction that
+ * got actually signed (i.e `directSignResponse.signed`) and
* the reason why is that the user can make some changes on the original
- * transaction (i.e change gas limit or gas prices) and the transaction
+ * transaction (i.e change gas limit or gas prices) and the transaction
* that get's signed and the one that gets broadcasted are not the same.
*/
-const directSignResponse = /* From the second step above */
+const directSignResponse = /* From the second step above */
const txRaw = getTxRawFromTxRawOrDirectSignResponse(directSignResponse)
const broadcastTx = async (chainId, txRaw) => {
@@ -134,7 +136,7 @@ const broadcastTx = async (chainId, txRaw) => {
const keplr = await getKeplr(ChainId.Mainnet)
const result = await keplr.sendTx(
chainId,
- txRaw.serializeBinary(),
+ CosmosTxV1Beta1Tx.TxRaw.encode(txRaw).finish(),
BroadcastMode.Sync,
)
@@ -150,10 +152,10 @@ const broadcastTx = async (chainId, txRaw) => {
const txHash = await broadcastTx(ChainId.Mainnet, txRaw)
-/**
- * Once we get the txHash, because we use the Sync mode we
- * are not sure that the transaction is included in the block,
- * it can happen that it's still in the mempool so we need to query
+/**
+ * Once we get the txHash, because we use the Sync mode we
+ * are not sure that the transaction is included in the block,
+ * it can happen that it's still in the mempool so we need to query
* the chain to see when the transaction will be included
*/
const restEndpoint = 'https://lcd.injective.network' /* getNetworkEndpoints(Network.Mainnet).rest */
@@ -168,24 +170,28 @@ const response = await txRestClient.fetchTxPoll(txHash)
Let's have a look at the whole flow (using Keplr as a signing wallet)
```ts
-import {
+import {
MsgSend,
- ChainRestAuthApi,
- ChainRestTendermintApi,
BaseAccount,
DEFAULT_STD_FEE,
+ ChainRestAuthApi,
createTransaction,
+ CosmosTxV1Beta1Tx,
+ ChainRestTendermintApi,
} from '@injectivelabs/sdk-ts'
-import { DEFAULT_STD_FEE, DEFAULT_BLOCK_TIMEOUT_HEIGHT } from '@injectivelabs/utils'
+import {
+ DEFAULT_STD_FEE,
+ DEFAULT_BLOCK_TIMEOUT_HEIGHT,
+} from '@injectivelabs/utils'
import { ChainId } from '@injectivelabs/ts-types'
import { Network, getNetworkEndpoints } from '@injectivelabs/networks'
const getKeplr = async (chainId) => {
- await window.keplr.enable(chainId);
-
- const offlineSigner = window.keplr.getOfflineSigner(chainId);
- const accounts = await offlineSigner.getAccounts();
- const key = await window.keplr.getKey(chainId);
+ await window.keplr.enable(chainId)
+
+ const offlineSigner = window.keplr.getOfflineSigner(chainId)
+ const accounts = await offlineSigner.getAccounts()
+ const key = await window.keplr.getKey(chainId)
return { offlineSigner, accounts, key }
}
@@ -194,7 +200,7 @@ const broadcastTx = async (chainId, txRaw) => {
const keplr = await getKeplr(ChainId.Mainnet)
const result = await keplr.sendTx(
chainId,
- txRaw.serializeBinary(),
+ CosmosTxV1Beta1Tx.TxRaw.encode(txRaw).finish(),
BroadcastMode.Sync,
)
@@ -210,16 +216,15 @@ const broadcastTx = async (chainId, txRaw) => {
const injectiveAddress = 'inj1'
const chainId = 'injective-1' /* ChainId.Mainnet */
-const restEndpoint = 'https://lcd.injective.network' /* getNetworkEndpoints(Network.Mainnet).rest */
+const restEndpoint =
+ 'https://lcd.injective.network' /* getNetworkEndpoints(Network.Mainnet).rest */
const amount = {
amount: new BigNumberInBase(0.01).toWei().toFixed(),
- denom: "inj",
-};
+ denom: 'inj',
+}
/** Account Details **/
-const chainRestAuthApi = new ChainRestAuthApi(
- restEndpoint,
-)
+const chainRestAuthApi = new ChainRestAuthApi(restEndpoint)
const accountDetailsResponse = await chainRestAuthApi.fetchAccount(
injectiveAddress,
)
@@ -227,9 +232,7 @@ const baseAccount = BaseAccount.fromRestApi(accountDetailsResponse)
const accountDetails = baseAccount.toAccountDetails()
/** Block Details */
-const chainRestTendermintApi = new ChainRestTendermintApi(
- restEndpoint,
-)
+const chainRestTendermintApi = new ChainRestTendermintApi(restEndpoint)
const latestBlock = await chainRestTendermintApi.fetchLatestBlock()
const latestHeight = latestBlock.header.height
const timeoutHeight = new BigNumberInBase(latestHeight).plus(
@@ -241,7 +244,7 @@ const msg = MsgSend.fromJSON({
amount,
srcInjectiveAddress: injectiveAddress,
dstInjectiveAddress: injectiveAddress,
-});
+})
/** Get the PubKey of the Signer from the Wallet/Private Key */
const pubKey = await getPubKey()
@@ -257,7 +260,10 @@ const { txRaw, signDoc } = createTransaction({
accountNumber: baseAccount.accountNumber,
})
-const directSignResponse = await offlineSigner.signDirect(injectiveAddress, signDoc)
+const directSignResponse = await offlineSigner.signDirect(
+ injectiveAddress,
+ signDoc,
+)
const txRaw = getTxRawFromTxRawOrDirectSignResponse(directSignResponse)
const txHash = await broadcastTx(ChainId.Mainnet, txRaw)
const response = await new TxRestClient(restEndpoint).fetchTxPoll(txHash)
@@ -265,8 +271,4 @@ const response = await new TxRestClient(restEndpoint).fetchTxPoll(txHash)
### Example with WalletStrategy (Prepare + Sign + Broadcast)
-🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧
-
-This part is currently under work in progress.
-
-🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧
+Example can be found [here](https://github.com/InjectiveLabs/injective-ts/blob/862e7c30d96120947b056abffbd01b4f378984a1/packages/wallet-ts/src/broadcaster/MsgBroadcaster.ts#L301-L365).
diff --git a/.gitbook/wallet/wallet-connections.md b/.gitbook/wallet/wallet-connections.md
index 4a802f182..0a76bf647 100644
--- a/.gitbook/wallet/wallet-connections.md
+++ b/.gitbook/wallet/wallet-connections.md
@@ -1,7 +1,73 @@
# Wallet Connections
-🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧
+Injective supports both Ethereum and Cosmos native wallets. You can use popular wallets like Metamask, Ledger, Keplr, Leap, etc. to sign transactions on Injective.
-This wiki page is currently under work in progress.
+### Wallet Strategy
-🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧 🚧
+The recommended way to have support for all of these wallets out of the box is to use the [WalletStrategy](wallet-wallet-strategy.md) abstraction we've built. This approach will enable your dApp users to connect and interact with different wallets.
+
+Combining it with the [MsgBroadcaster](../transactions/msgbroadcaster.md) abstraction allows you to sign transactions using one function call. This is what's being used on all products like Helix, Hub, Explorer, etc., and we strongly recommend using this approach in your dApp.
+
+In case you still want to use some wallet natively (without the WalletStrategy class), we are going to provide examples of how to connect to a dApp built on Injective via Metamask and Keplr in this doc.
+
+### Metamask
+
+Metamask is an Ethereum native wallet and can be used to connect and interact with your dApp built on Injective.
+
+* **Get Injective addresses from Metamask**
+
+
+import { getInjectiveAddress } from '@injectivelabs/sdk-ts'
+
+const getEthereum = () => {
+ if (!window.ethereum) {
+ throw new Error('Metamask extension not installed')
+ }
+
+ return window.ethereum
+}
+
+const ethereum = getEthereum()
+const addresses = await ethereum.request({
+ method: 'eth_requestAccounts',
+}) /** these are evm addresses */
+
+const injectiveAddresses = addresses.map(getInjectiveAddress)
+console.log(injectiveAddresses)
+
+
+* **Sign transactions using Metamask**
+
+An example of how to prepare + sign + broadcast a transaction on Injective using Metamask can be found [here](../transactions/ethereum.md).
+
+### Keplr
+
+Keplr is an Cosmos native wallet and can be used to connect and interact with your dApp built on Injective.
+
+* **Get Injective addresses from Keplr**
+
+