# Local OJX Network

See also : <https://github.com/ethereum/go-ethereum/wiki/Private-network>

### Setting up your OJX Node(s) <a href="#setting-up-your-ojx-nodes" id="setting-up-your-ojx-nodes"></a>

#### 1. Prereq : Install Geth <a href="#id-1-prereq-install-geth" id="id-1-prereq-install-geth"></a>

Review the guide [here](https://docs.ojxscan.com/smart-chain/developer/fullnode.html)

#### 2. Prereq : create /projects <a href="#id-2-prereq-create-projects" id="id-2-prereq-create-projects"></a>

Create a `/projects` symbolic link *(Note: This step is simply so "/projects" can be used in all other commands, instead you could use full paths, or set an env var)*

```
$ mkdir <my projects folder>
$ sudo ln -s <my projects folder> /projects
```

#### 3. Create local\_ethereum\_blockchain folder <a href="#id-3-create-local_ethereum_blockchain-folder" id="id-3-create-local_ethereum_blockchain-folder"></a>

```
$ mkdir /projects/local_ethereum_blockchain
```

#### 4. Create the genesis block config <a href="#id-4-create-the-genesis-block-config" id="id-4-create-the-genesis-block-config"></a>

Create this file : `/projects/local_ethereum_blockchain/genesis.json`

With the following contents :

```
{
     "config": {
       "chainId": 1000,
       "homesteadBlock": 0,
       "eip155Block": 0,
       "eip158Block": 0
                },
     "nonce": "0x0000000000000061",
     "timestamp": "0x0",
     "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
     "gasLimit": "0x8000000",
     "difficulty": "0x100",
     "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
     "coinbase": "0x3333333333333333333333333333333333333333",
     "alloc": {}
}
```

([info about the genesis file](https://ethereum.stackexchange.com/a/2377/2040))

#### 5. Initialise an Ethereum node <a href="#id-5-initialise-an-ethereum-node" id="id-5-initialise-an-ethereum-node"></a>

```
$ geth --datadir /projects/local_ethereum_blockchain/node1 init /projects/local_ethereum_blockchain/genesis.json
```

#### 6. Start that Ethereum node <a href="#id-6-start-that-ethereum-node" id="id-6-start-that-ethereum-node"></a>

```
$ geth --datadir /projects/local_ethereum_blockchain/node1 --networkid 1000 console
```

#### 7. Initialise another Ethereum node <a href="#id-7-initialise-another-ethereum-node" id="id-7-initialise-another-ethereum-node"></a>

```
$ geth --datadir /projects/local_ethereum_blockchain/node-2 init /projects/local_ethereum_blockchain/genesis.json
```

#### 8. Start the 2nd Ethereum node <a href="#id-8-start-the-2nd-ethereum-node" id="id-8-start-the-2nd-ethereum-node"></a>

```
$ geth --datadir /projects/local_ethereum_blockchain/node-2 --port 30304 --nodiscover --networkid 1000 console
```

#### 9. Connect one node to the other <a href="#id-9-connect-one-node-to-the-other" id="id-9-connect-one-node-to-the-other"></a>

In one geth console :

```
> admin.nodeInfo.enode
```

In the other console :

```
> admin.addPeer( <the enode value from the first console> )
```

### Useful geth commands <a href="#useful-geth-commands" id="useful-geth-commands"></a>

#### Node info <a href="#node-info" id="node-info"></a>

```
> admin.nodeInfo
```

#### Peers <a href="#peers" id="peers"></a>

Show peers

```
> admin.peers
```

How many peers ?

```
> admin.peers.length
```

#### Create an account <a href="#create-an-account" id="create-an-account"></a>

You need an account to do be able to do things like mining

```
> personal.newAccount()
```

*And make sure your remember/save the password!*

#### Unlock account <a href="#unlock-account" id="unlock-account"></a>

Neccessary before some actions

```
> personal.unlockAccount( eth.accounts[0] )
```

#### Start mining <a href="#start-mining" id="start-mining"></a>

```
> miner.start(1)
```

The first block may take a while to mine, allow a few minutes

#### Stop mining <a href="#stop-mining" id="stop-mining"></a>

```
> miner.stop()
```

#### Current block number <a href="#current-block-number" id="current-block-number"></a>

```
> eth.blockNumber
```

#### Details of current block <a href="#details-of-current-block" id="details-of-current-block"></a>

```
> eth.getBlock( eth.blockNumber )
```

#### Which node minded the last block <a href="#which-node-minded-the-last-block" id="which-node-minded-the-last-block"></a>

```
> eth.getBlock(eth.blockNumber).miner
```

#### Account balance, in ether <a href="#account-balance-in-ether" id="account-balance-in-ether"></a>

```
> web3.fromWei(eth.getBalance(eth.accounts[0]))
```

#### Transfer ether between accounts <a href="#transfer-ether-between-accounts" id="transfer-ether-between-accounts"></a>

First get the account numbers by doing

`> eth.accounts`

Then unlock the account you are sending from

`> personal.unlockAccount( <from account> )`

eg.

`> personal.unlockAccount(eth.accounts[0])`

Finally transfer 1 ether

```
> eth.sendTransaction({from: "<from account>", to: "<to account>", value: web3.toWei(1, "ether")})
```

#### Exit <a href="#exit" id="exit"></a>

```
> exit
```

(This will also stop the node from running if it was started using `$ geth console` (as opposed to `$ geth attach`))

### Connect to other nodes on your network <a href="#connect-to-other-nodes-on-your-network" id="connect-to-other-nodes-on-your-network"></a>

1. Get the IP of the node : `$ ifconfig|grep netmask|awk '{print $2}'`
2. Get the enode of the node : `> admin.nodeInfo.enode`
3. REPLACE `[::]` in the enode string with the `[<ip address>]`
4. On your console `> admin.addPeer(< the enode string with the ip address in it>)`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://oja.gitbook.io/oja-coin/oja-smart-chain-ojx20/developers/tutorial/local-ojx-network.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
