# Accounts

{% hint style="info" %}
**Abobi**

Dis document go yarn about something important for Injective Chain: **how dem keep track of your money.**
{% endhint %}

{% hint style="warning" %}
**Abeg, before you jump into di main thing, read dis one first.**

* [Cosmos SDK Accounts](https://docs.cosmos.network/main/basics/accounts)
* [Ethereum Accounts](https://ethereum.org/en/whitepaper/#ethereum-accounts)
  {% endhint %}

## Accounts for Injective <a href="#injective-accounts" id="injective-accounts"></a>

Injective don make ein own account as dem want am, dis na `Account` type wey dey use Ethereum's ECDSA secp256k1 curve for keys. Ein dey belleful di [EIP84](https://github.com/ethereum/EIPs/issues/84) for full [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) paths. Di main di main HD path for Injective-based accounts na `m/44'/60'/0'/0`.

## Addresses and Public Keys <a href="#addresses-and-public-keys" id="addresses-and-public-keys"></a>

Na 3 Ogbonke `Addresses`/`PubKeys` dey from di start as dem make Injective:

* One na di Addresses and Keys for **accounts**, wey dey see users (e.g. the sender of a `message`). Dem dey get am are with di **`eth_secp256k1`** curve.
* Another na di Addresses and Keys for **validator operators**, wey dey put eye for di operators of validators. You fit use d&#x69;**`eth_secp256k1`** curve get am.
* Another come be di Addresses and Keys for **consensus nodes**, e dey identify divalidator nodes wey dey put mouth for consensus. You fit use d&#x69;**`ed25519`** curve get am.

|                    | Address bech32 Prefix | Pubkey bech32 Prefix | Curve           | Address byte length | Pubkey byte length |
| ------------------ | --------------------- | -------------------- | --------------- | ------------------- | ------------------ |
| Accounts           | `inj`                 | `injpub`             | `eth_secp256k1` | `20`                | `33` (compressed)  |
| Validator Operator | `injvaloper`          | `injvaloperpub`      | `eth_secp256k1` | `20`                | `33` (compressed)  |
| Consensus Nodes    | `injvalcons`          | `injvalconspub`      | `ed25519`       | `20`                | `32`               |

## Address formats for clients <a href="#address-formats-for-clients" id="address-formats-for-clients"></a>

`EthAccount` fit turn up as [Bech32](https://en.bitcoin.it/wiki/Bech32) and hex format wey dem dey use for Ethereum's Web3 tooling compatibility.

Di Bech32 format na di default format wey dem dey use for Cosmos-SDK queries and transactions through CLI and REST clients. Di hex format for di other hand, na di Ethereum `common.Address` representation of a Cosmos `sdk.AccAddress`.

* Address (Bech32): `inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku`
* Address ([EIP55](https://eips.ethereum.org/EIPS/eip-55) Hex): `0xAF79152AC5dF276D9A8e1E2E22822f9713474902`
* Compressed Public Key: `{"@type":"/injective.crypto.v1beta1.ethsecp256k1.PubKey","key":"ApNNebT58zlZxO2yjHiRTJ7a7ufjIzeq5HhLrbmtg9Y/"}`

You fit use Cosmos CLI or REST clients query account address

{% code overflow="wrap" fullWidth="true" %}

```javascript
# NOTE: the --output (-o) flag will define the output format in JSON or YAML (text)
injectived q auth account $(injectived keys show <MYKEY> -a) -o text
|
  '@type': /injective.types.v1beta1.EthAccount
  base_account:
    account_number: "3"
    address: inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku
    pub_key: null
    sequence: "0"
  code_hash: xdJGAYb3IzySfn2y3McDwOUAtlPKgic7e/rYBF2FpHA=
```

{% endcode %}

{% code overflow="wrap" %}

```javascript
# GET /cosmos/auth/v1beta1/accounts/{address}
curl -X GET "http://localhost:10337/cosmos/auth/v1beta1/accounts/inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku" -H "accept: application/json"
```

{% endcode %}

Check di [Swagger API](https://lcd.injective.network/swagger/) reference for thedi full gist on top accounts API matter.

::: tip The Cosmos SDK Keyring output (i.e `injectived keys`) dey only supports addresses in Bech32 format. :::

## Deriving Injective Account from a private key/mnemonic[​](https://docs.injective.network/learn/basic-concepts/accounts#deriving-injective-account-from-a-private-keymnemonic) <a href="#deriving-injective-account-from-a-private-keymnemonic" id="deriving-injective-account-from-a-private-keymnemonic"></a>

Make we see how di code go be to derive Injective Account from a private key and/or a mnemonic phase:

{% code overflow="wrap" %}

```javascript
import { Wallet } from 'ethers'
import { Address as EthereumUtilsAddress } from 'ethereumjs-util'

const mnemonic = "indoor dish desk flag debris potato excuse depart ticket judge file exit"
const privateKey = "afdfd9c3d2095ef696594f6cedcae59e72dcd697e2a7521b1578140422a4f890"
const defaultDerivationPath = "m/44'/60'/0'/0/0"
const defaultBech32Prefix = 'inj'
const isPrivateKey: boolean = true /* just for the example */

const wallet = isPrivateKey ? Wallet.fromMnemonic(mnemonic, defaultDerivationPath) : new Wallet(privateKey)
const ethereumAddress = wallet.address
const addressBuffer = EthereumUtilsAddress.fromString(ethereumAddress.toString()).toBuffer()
const injectiveAddress = bech32.encode(defaultBech32Prefix, bech32.toWords(addressBuffer))
```

{% endcode %}

Make we put eye for how code to derive a public key from a private key dey:

{% code overflow="wrap" %}

```javascript
import secp256k1 from 'secp256k1'

const privateKey = "afdfd9c3d2095ef696594f6cedcae59e72dcd697e2a7521b1578140422a4f890"
const privateKeyHex = Buffer.from(privateKey.toString(), 'hex')
const publicKeyByte = secp256k1.publicKeyCreate(privateKeyHex)

const buf1 = Buffer.from([10])
const buf2 = Buffer.from([publicKeyByte.length])
const buf3 = Buffer.from(publicKeyByte)

const publicKey = Buffer.concat([buf1, buf2, buf3]).toString('base64')
const type = '/injective.crypto.v1beta1.ethsecp256k1.PubKey'
```

{% endcode %}
