From 3f1a2232b5e978c56fc6406092c5895b686030ff Mon Sep 17 00:00:00 2001 From: Bojan Angjelkoski Date: Tue, 8 Oct 2024 13:50:49 +0000 Subject: [PATCH] GITBOOK-78: change request with no subject merged in GitBook --- .gitbook/README.md | 35 +++++++++++++++++------------- .gitbook/wallet/wallet-accounts.md | 35 ++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/.gitbook/README.md b/.gitbook/README.md index a9331616a..511097bd5 100644 --- a/.gitbook/README.md +++ b/.gitbook/README.md @@ -1,35 +1,40 @@ # Getting Started -**Stable Package Version** +**Supported Node Versions ****> 18x** -![](https://img.shields.io/npm/v/%40injectivelabs/sdk-ts/latest?label=%40injectivelabs%2Fsdk-ts)![Stable Package (all) versions](https://img.shields.io/npm/v/%40injectivelabs/wallet-ts/latest?label=%40injectivelabs%2Fwallet-ts) -![](https://img.shields.io/npm/v/%40injectivelabs/networks/latest?label=%40injectivelabs%2Fnetworks)![](https://img.shields.io/npm/v/%40injectivelabs/ts-types/latest?label=%40injectivelabs%2Fts-types)![](https://img.shields.io/npm/v/%40injectivelabs/utils/latest?label=%40injectivelabs%2Futils) +
-![Supported Node Version](http://img.shields.io/badge/node-18.x-brightgreen.svg) +Supported Node Version -**Deprecated Packages:** +
+ +**Stable Package Version** -![](https://img.shields.io/npm/v/%40injectivelabs/bridge-ts/latest?label=%40injectivelabs%2Fbridge-ts)![](https://img.shields.io/npm/v/%40injectivelabs/contracts/latest?label=%40injectivelabs%2Fcontracts)![](https://img.shields.io/npm/v/%40injectivelabs/sdk-ui-ts/latest?label=%40injectivelabs%2Fsdk-ui-ts)![](https://img.shields.io/npm/v/%40injectivelabs/token-utils/latest?label=%40injectivelabs%2Ftoken-utils)![](https://img.shields.io/npm/v/%40injectivelabs%2Ftoken-metadata/latest?label=%40injectivelabs%2Ftoken-metadata) +![](https://img.shields.io/npm/v/%40injectivelabs/sdk-ts/latest?label=%40injectivelabs%2Fsdk-ts) ![](https://img.shields.io/npm/v/%40injectivelabs/wallet-ts/latest?label=%40injectivelabs%2Fwallet-ts) ![](https://img.shields.io/npm/v/%40injectivelabs/networks/latest?label=%40injectivelabs%2Fnetworks) ![](https://img.shields.io/npm/v/%40injectivelabs/ts-types/latest?label=%40injectivelabs%2Fts-types) ![](https://img.shields.io/npm/v/%40injectivelabs/utils/latest?label=%40injectivelabs%2Futils) **Latest Package Versions:** -![](https://img.shields.io/npm/v/%40injectivelabs/sdk-ts/next?label=%40injectivelabs%2Fsdk-ts)![](https://img.shields.io/npm/v/%40injectivelabs/wallet-ts/next?label=%40injectivelabs%2Fwallet-ts)![](https://img.shields.io/npm/v/%40injectivelabs/networks/next?label=%40injectivelabs%2Fnetworks)![](https://img.shields.io/npm/v/%40injectivelabs/ts-types/next?label=%40injectivelabs%2Fts-types)![](https://img.shields.io/npm/v/%40injectivelabs/utils/next?label=%40injectivelabs%2Futils) +![](https://img.shields.io/npm/v/%40injectivelabs/sdk-ts/next?label=%40injectivelabs%2Fsdk-ts) ![](https://img.shields.io/npm/v/%40injectivelabs/wallet-ts/next?label=%40injectivelabs%2Fwallet-ts) ![](https://img.shields.io/npm/v/%40injectivelabs/networks/next?label=%40injectivelabs%2Fnetworks) ![](https://img.shields.io/npm/v/%40injectivelabs/ts-types/next?label=%40injectivelabs%2Fts-types) ![](https://img.shields.io/npm/v/%40injectivelabs/utils/next?label=%40injectivelabs%2Futils) -_**Note:** The latest versions are published using the `next` tag. For stable versions use the `latest` tag or check npm registry for the latest stable version._ +_**Note:** The latest versions are published using the `next` tag. For stable versions use the `latest` tag or check npm registry for the latest stable version._ The purpose of this Wiki is to help developers build decentralized applications on top of Injective. Let's dive a bit deeper into each section and explain its purpose so its easier to get the bigger picture. _Note: Reading the Technical Concepts section after reading the overview below is highly recommended. There are some concepts that can have a bit steeper learning curve than others, so we recommend going through them to understand a bit more about Injective._ -- [Wallets](wallet/) - In this section, we are going to explain (in technical terms) how Accounts are derived on Injective, how you can connect your wallet straight from the dApp itself, and finally have a look at the **WalletStrategy** - a package built by the InjectiveLabs team which offers out of the box solution for providing multiple wallet solutions to the user to connect and interact with your dApp. -- [Querying](querying/) - In this section we are going to explore different ways to obtain data from different data sources needed to build your dApps. First, we are going to see how to query the chain directly and then we are going to explore the Indexer API - an indexer solution for easier data access/streaming including historical data. -- [Transaction](transactions/) - In this section, we are going to explore different ways to make transactions on Injective. First, we are going to explain (in technical terms) how Transactions work on Injective and some technical concepts around them and then we are going to have a look at how to prepare, sign, and broadcast transactions on Injective in several ways. There are a couple of ways to do this. +* [Wallets](wallet/) - In this section, we are going to explain (in technical terms) how Accounts are derived on Injective, how you can connect your wallet straight from the dApp itself, and finally have a look at the **WalletStrategy** - a package built by the InjectiveLabs team which offers out of the box solution for providing multiple wallet solutions to the user to connect and interact with your dApp. +* [Querying](querying/) - In this section we are going to explore different ways to obtain data from different data sources needed to build your dApps. First, we are going to see how to query the chain directly and then we are going to explore the Indexer API - an indexer solution for easier data access/streaming including historical data. +* [Transaction](transactions/) - In this section, we are going to explore different ways to make transactions on Injective. First, we are going to explain (in technical terms) how Transactions work on Injective and some technical concepts around them and then we are going to have a look at how to prepare, sign, and broadcast transactions on Injective in several ways. There are a couple of ways to do this. 1. Using the Cosmos native approach in creating a transaction, sign it using a **Cosmos native wallet** and broadcast it to Injective, 2. Using the Ethereum native approach in creating a transaction using EIP712 typed data, sign it using an **Ethereum native wallet** and broadcast it to Injective, 3. Using the Ethereum native approach in creating a transaction using EIP712 typed data, sign it using a **Ledger device** and broadcast it to Injective, 4. Using the Cosmos native approach in creating a transaction, sign it using a **raw PrivateKey** and broadcast it to Injective, 5. Using the Web3Gateway microservice - an API that provides fee delegation services. -- [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. +* [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. + +**Deprecated Packages:** + +![](https://img.shields.io/npm/v/%40injectivelabs/bridge-ts/latest?label=%40injectivelabs%2Fbridge-ts) ![](https://img.shields.io/npm/v/%40injectivelabs/contracts/latest?label=%40injectivelabs%2Fcontracts) ![](https://img.shields.io/npm/v/%40injectivelabs/sdk-ui-ts/latest?label=%40injectivelabs%2Fsdk-ui-ts) ![](https://img.shields.io/npm/v/%40injectivelabs/token-utils/latest?label=%40injectivelabs%2Ftoken-utils) ![](https://img.shields.io/npm/v/%40injectivelabs%2Ftoken-metadata/latest?label=%40injectivelabs%2Ftoken-metadata) diff --git a/.gitbook/wallet/wallet-accounts.md b/.gitbook/wallet/wallet-accounts.md index 8d2bef0c9..bd18775de 100644 --- a/.gitbook/wallet/wallet-accounts.md +++ b/.gitbook/wallet/wallet-accounts.md @@ -93,3 +93,38 @@ const buf3 = Buffer.from(publicKeyByte) const publicKey = Buffer.concat([buf1, buf2, buf3]).toString('base64') const type = '/injective.crypto.v1beta1.ethsecp256k1.PubKey' ``` + +#### Convert Cosmos address to Injective Address + +As Injective has a different derivation path than the default Cosmos one, you need the `publicKey` of the account to convert a Cosmos `publicAddress` to Injective one. + +Here is an example of how to do it + +```typescript +import { config } from "dotenv"; +import { ChainRestAuthApi, PublicKey } from "@injectivelabs/sdk-ts"; + +config(); + +(async () => { + const chainApi = new ChainRestAuthApi( + "https://rest.cosmos.directory/cosmoshub" + ); + + const cosmosAddress = "cosmos1.."; + const account = await chainApi.fetchCosmosAccount(cosmosAddress); + + if (!account.pub_key?.key) { + console.log("No public key found"); + return; + } + + console.log( + "injectiveAddress", + PublicKey.fromBase64(account.pub_key.key || "") + .toAddress() + .toBech32() + ); +})(); + +```