> For the complete documentation index, see [llms.txt](https://worldkoisan.gitbook.io/koisan-international-coin/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://worldkoisan.gitbook.io/koisan-international-coin/koisan-chain/dapp-development/account-management.md).

# Account Management

Wallet Account Management

Some interfaces that interact with the chain have been encapsulated by `web3` to facilitate our `DApp` development. Via theses `web3` encapsulated interfaces, we can use different languages to interact with `KIC`. This article elaborates on how to use `JavaScript` and `Python` to manage accounts on `KIC` through `Web3`.

## Create instances of `web3` <a href="#create-instances-of-web3" id="create-instances-of-web3"></a>

### Javascript

Mostly, `javascript` uses database[`web3.js`](https://web3js.readthedocs.io/en/v1.3.4/) to interact with `KIC`.

* Connect to Mainnet

```
const w3 = new Web3("https://rpc.koisan-chain");
```

* Connect to Testnet

```
const w3 = new Web3("https://testnet-rpc.koisan-chain");
```

### Python3

Mostly, `python` uses package[`Web3.py`](https://web3py.readthedocs.io/en/stable/)to interact with `KIC`.

* Connect to Mainnet

```
from web3 import Web3
from web3.middleware import geth_poa_middleware
provider = Web3.HTTPProvider("https://rpc.koisan-chain")
w3 = Web3(provider)
w3.middleware_onion.inject(geth_poa_middleware, layer=0)
```

* Connect to Testnet

```
from web3 import Web3
from web3.middleware import geth_poa_middleware
provider = Web3.HTTPProvider("https://testnet-rpc.koisan-chain")
w3 = Web3(provider)
w3.middleware_onion.inject(geth_poa_middleware, layer=0)
```

## Create an Account

After instantiating `web3`, you can return a random account with the following call:

### Javascript <a href="#javascript-1" id="javascript-1"></a>

```
const account = w3.eth.accounts.create();
// print account
console.log(account);
/*
example:
{
  address: '0x00DE048c92eF8D6FeC6275E1907E38798808005d',
  privateKey: '0xc2a58a08abcd566348a6d2798b0b074fc8b7b66a650a7aaf463e6d36b4b9776e',
  signTransaction: [Function: signTransaction],
  sign: [Function: sign],
  encrypt: [Function: encrypt]
}
*/
```

### Python3 <a href="#python" id="python"></a>

```
account = w3.eth.account.create();
# print private key
print(account.privateKey.hex())
# example: `0x9b308e83c8120818a721fc999618d8869da61c0b440386b963523bcb26fe9839'

# print address
print(account.address)
# example: '0xC286d47ABE4C9B8B2F724610B9eb9e91D7a7De9A'
```

## Recover Account Via Private Key

You can also recover your account on `KIC` directly through `web3` if you have access to your private key.

### Javascript <a href="#javascript-2" id="javascript-2"></a>

```
const account = w3.eth.accounts.privateKeyToAccount("your private key string")
```

### Python3 <a href="#python3-1" id="python3-1"></a>

```
account = w3.eth.account.privateKeyToAccount("your private key string")
```
