Accounts

Injective defines its own custom Account type that uses Ethereum's ECDSA secp256k1 curve for keys. This satisfies the EIP84 for full BIP44 paths. The root HD path for Injective-based accounts is m/44'/60'/0'/0.

Address conversion

You can easily convert between an Injective address and Ethereum address by using our utility functions in the @injectivelabs/sdk-ts package:

import { getInjectiveAddress, getEthereumAddress } from '@injectivelabs/sdk-ts'

const injectiveAddress = 'inj1...'
const ethereumAddress = '0x..'

console.log('Injective address from Ethereum address => ', getInjectiveAddress(ethereumAddress))
console.log('Ethereum address from Injective address => ', getEthereumAddress(injectiveAddress))

Deriving wallets

Using Injective utility classes

  • Example code snippet on how to derive Injective Account from a private key and/or a mnemonic phrase:

import { PrivateKey } from '@injectivelabs/sdk-ts'

const mnemonic = "indoor dish desk flag debris potato excuse depart ticket judge file exit"
const privateKey = "afdfd9c3d2095ef696594f6cedcae59e72dcd697e2a7521b1578140422a4f890"
const privateKeyFromMnemonic = PrivateKey.fromMnemonic(mnemonic)
const privateKeyFromHex = PrivateKey.fromPrivateKey(privateKey)

const address = privateKeyFromMnemonic.toAddress() /* or privateKeyFromHex.toAddress() */
console.log({ injectiveAddress: address.toBech32(), ethereumAddress: address.toHex() })
  • Example code snipped on how to derive a public address from a public key:

  • Example code snipped on how to derive an address from a private key:

Without using Injective utility classes

  • Example code snippet on how to derive Injective Account from a private key and/or a mnemonic phrase:

  • Example code snipped on how to derive a public key from a private key:

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

Last updated