Private Etherium Blockchain Model

Private Etherium Blockchain Model




🛑 👉🏻👉🏻👉🏻 INFORMATION AVAILABLE CLICK HERE👈🏻👈🏻👈🏻





















































{
"config" : {
"chainId" : 731 ,
"homesteadBlock" : 0
} ,
"difficulty" : "0x400" ,
"gasLimit" : "0x8000000" ,
"alloc" : { }
}


geth -datadir ./blockchain init ./genesis.json


INFO [ 06-19 | 13:12:14 ] Maximum peer count ETH = 25 LES = 0 total = 25
INFO [ 06-19 | 13:12:14 ] Allocated cache and file handles database = < my-working-dir > \blockchain\geth\chaindata cache = 16 handles = 16
INFO [ 06-19 | 13:12:14 ] Writing custom genesis block
INFO [ 06-19 | 13:12:14 ] Persisted trie from memory database nodes = 0 size = 0.00B time = 0s gcnodes = 0 gcsize = 0.00B gctime = 0s livenodes = 1 livesize = 0.00B
INFO [ 06-19 | 13:12:14 ] Successfully wrote genesis state database = chaindata hash = d1a12d…4c8725
INFO [ 06-19 | 13:12:14 ] Allocated cache and file handles database = < my-working-dir > \blockchain\geth\lightchaindata cache = 16 handles = 16
INFO [ 06-19 | 13:12:15 ] Writing custom genesis block
INFO [ 06-19 | 13:12:15 ] Persisted trie from memory database nodes = 0 size = 0.00B time = 0s gcnodes = 0 gcsize = 0.00B gctime = 0s livenodes = 1 livesize = 0.00B
INFO [ 06-19 | 13:12:15 ] Successfully wrote genesis state database = lightchaindata hash = d1a12d…4c8725


geth --datadir ./blockchain --networkid 7314 --ws --wsorigins "http://localhost:8080,http://" --wsapi = "eth,web3,personal,miner" --gasprice 0


INFO [ 06-19 | 13:45:55 ] Maximum peer count ETH = 25 LES = 0 total = 25
INFO [ 06-19 | 13:45:55 ] Starting peer-to-peer node instance = Geth/v1.8.10-stable-eae63c51/windows-amd64/go1.10.2
INFO [ 06-19 | 13:45:55 ] Allocated cache and file handles database = < my-working-dir > \blockchain\geth\chaindata cache = 768 handles = 1024
INFO [ 06-19 | 13:45:55 ] Initialised chain configuration config = "{ChainID: 731 Homestead: 0 DAO: DAOSupport: false EIP150: EIP155: EIP158: Byzantium: Constantinople: Engine: unknown}"
INFO [ 06-19 | 13:45:55 ] Disk storage enabled for ethash caches dir = < my-working-dir > \blockchain\geth\ethash count = 3
INFO [ 06-19 | 13:45:55 ] Disk storage enabled for ethash DAGs dir = C:\AppData\Ethash count = 2
INFO [ 06-19 | 13:45:55 ] Initialising Ethereum protocol versions = "[63 62]" network = 7314
INFO [ 06-19 | 13:45:55 ] Loaded most recent local header number = 0 hash = d1a12d…4c8725 td = 1024
INFO [ 06-19 | 13:45:55 ] Loaded most recent local full block number = 0 hash = d1a12d…4c8725 td = 1024
INFO [ 06-19 | 13:45:55 ] Loaded most recent local fast block number = 0 hash = d1a12d…4c8725 td = 1024
INFO [ 06-19 | 13:45:55 ] Regenerated local transaction journal transactions = 0 accounts = 0
INFO [ 06-19 | 13:45:55 ] Starting P2P networking
INFO [ 06-19 | 13:45:57 ] UDP listener up self = enode://939c12fbde8d140e55800327c8b5fcd71a81a32647b95a89840580f67628cf4a650974af1c28588c1df476400cbaa6d514b23d0d14919f04ece8da52e6f7fcf5@ [ :: ] :30303
INFO [ 06-19 | 13:45:57 ] RLPx listener up self = enode://939c12fbde8d140e55800327c8b5fcd71a81a32647b95a89840580f67628cf4a650974af1c28588c1df476400cbaa6d514b23d0d14919f04ece8da52e6f7fcf5@ [ :: ] :30303
INFO [ 06-19 | 13:45:57 ] IPC endpoint opened url = \\.\pipe\geth.ipc
INFO [ 06-19 | 13:45:57 ] WebSocket endpoint opened url = ws://127.0.0.1:8546


INFO [ 06-19 | 14:34:39 ] Starting mining operation
INFO [ 06-19 | 14:34:39 ] Commit new mining work number = 1 txs = 1 uncles = 0 elapsed = 0s
INFO [ 06-19 | 14:34:43 ] Successfully sealed new block number = 1 hash = 0d5b6c…978671
INFO [ 06-19 | 14:34:43 ] 🔨 mined potential block number = 1 hash = 0d5b6c…978671
INFO [ 06-19 | 14:34:43 ] Commit new mining work number = 2 txs = 0 uncles = 0 elapsed = 0s
INFO [ 06-19 | 14:34:43 ] Successfully sealed new block number = 2 hash = 62f2bd…351578
INFO [ 06-19 | 14:34:43 ] 🔨 mined potential block number = 2 hash = 62f2bd…351578**


function checkPendingTransactions ( ) {
if ( eth . getBlock ( "pending" ) . transactions . length > 0 ) {
if ( eth . mining ) return ;

console . log ( "Mining pending transactions...\n" ) ;
miner . start ( 1 ) ;
} else {
if ( ! eth . mining ) return ;

miner . stop ( ) ;
console . log ( "Mining stopped.\n" ) ;
}
}

eth . filter ( "latest" , checkPendingTransactions ) ;
eth . filter ( "pending" , checkPendingTransactions ) ;
checkPendingTransactions ( ) ;


geth attach ws://localhost:8546 --preload ./lazyMine.js


import Web3 from "web3" ;

const web3 = new Web3 ( "ws://localhost:8546" ) ;


web3 . eth . personal . unlockAccount ( address , passphrase ) ;


web3 . eth . personal . newAccount ( passphrase ) ;


web3 . eth . personal . getAccounts ( ) ;


web3 . eth . sendTransaction ( transaction )


async function getMessages ( ) {
let startBlockNumber = lastBlockRead + 1 ;
let endBlockNumber = await web3 . eth . getBlockNumber ( ) ;

for ( var i = startBlockNumber ; i <= endBlockNumber ; i ++ ) {
var block = await web3 . eth . getBlock ( i , true ) ;
if ( block && block . transactions !== null ) {
for ( let tx of block . transactions ) {
handleTransaction ( tx ) ;
}
lastBlockRead = block . number ;
}
}
}


web3 . eth . subscribe ( "newBlockHeaders" , callback )

Recently there’s been a lot of fascination surrounding blockchains, and how they can be used to improve long-standing industry technologies. Because of this, we’ve been investigating the applications of blockchains in messaging platforms. I’ve developed a blockchain-based messaging web-app which treats the blockchain as the main data model to gain some hands-on experience working with a blockchain.
In this post I’ll detail my process and rationale behind creating a private Ethereum blockchain and a web-app which interacts with it, with the hopes of guiding anyone who’d like to try it for themselves. No Ethereum experience necessary!
You can check out my proof-of-concept web-app here , which contains the finished web-app and a simple readme with instructions for running the Ethereum network.
The first thing that’s needed to start playing around with Ethereum is a way to leverage the Ethereum protocol, which gives access to the tools needed to interact with Ethereum networks. There are C++ and Python implementations of the protocol, but I’ll be using Geth (the Go implementation) as it can be interacted with through the CLI, making it quick and easy to use. Even though I’m using Geth, any implementation can be used as they should provide similar capabilities.
Before we can create the Ethereum network, we’ll first need to create its blockchain (starting with a genesis block).
A blockchain is a data structure which builds upon itself over time, which means that it needs an initial structure to build upon - the genesis block! This block is defined by a genesis state file, which describes both the block’s parameters and some parameters which affect the operation of the Ethereum network.
I initialized the genesis block using a state file named genesis.json in my working directory. Here’s what my genesis.json file contains:
This is a fairly minimal genesis state file, as I’ve only defined the parameters that I need for my particular setup. I’ll give some explanation on what each parameter does:
config : An object containing the configuration of Ethereum. It doesn’t configure anything specific to the genesis block itself, but it defines how the Ethereum network will run.
Once you have a genesis state file, setting up the blockchain is easy-peasy. I ran the following command in my working directory to create the blockchain based on my genesis state file in a directory named blockchain :
If all goes well, the output looks something like this:
After creating the blockchain data, running a private network for the blockchain is simple thanks to Geth. Here’s the command I used to initialize my private Ethereum network (replacing with my device’s name):
I’ll explain why I passed those specific parameters below ( see here for a full list of viable options ):
With this, the private Ethereum network is running and transactions can be sent and mined to the blockchain! When running successfully, your ouput should look something like this:
With the server running, the network should be accessible through Geth. You can attach a Geth console to the network with the following command:
This attaches to the network through the websocket served at port 8546 (the default port for WS-RPC) and provides a javascript console for interacting with it.
If you see the error message: Fatal: Unable to attach to remote geth: bad status accompanied with the following warning in the network output: WARN [06-19|13:58:58] origin 'http://' not allowed on WS-RPC interface , then you need to pass the given device name to the -wsorigins option when running your network.
Now that we have a console attached to the network, we’ll need to create an account before we can do certain things on the network (like mining and sending transactions). This can be done with the function personal.newAccount() , which prompts twice for a passphrase and then outputs the new account’s address (which acts like an ID for our purposes). The address you are allocated should look something like this: 0xedfc0cea37e9ed3bc7927a81f0dcd393bc57c0e6 .
To test that the network is set up correctly, we’ll send a dummy transaction and mine it. First, your account needs to be unlocked so that you can send a transaction from it. Calling the function personal.unlockAccount("") and entering the passphrase when prompted will unlock the given account, otherwise an error will be thrown.
Next, we’ll send a transaction. The function ethereum.sendTransaction({from: "

Report Page