basics initializing a cx chain - SkycoinWikis/CXChains GitHub Wiki
HOME » CX » CX CHAINS » INITIALIZING A CX CHAIN
Initializing a CX Chain
Currently, CX has the newcoin command as a dependency (located in cmd/newcoin). In order to initialize a new CX chain, newcoin needs to create the cxcoin command (located in cmd/cxcoin) using the parameters defined in ./fiber.toml. This process should be simplified by mimicking the process defined by cmd/cxcoin/cxcoin.go in cxgo/main.go. In other words, instead of having to call the process defined by cxcoin, we can embed the process in CX to eliminate the newcoin and cxcoin dependencies.
The workflow – which occurs when running, for example, cx --blockchain --secret-key $SECRET_KEY --public-key $PUBLIC_KEY examples/blockchain/counter-bc.cx – is as follows:
newcoinis installed by runninggo install ./cmd/newcoin/...newcoinis run in order to createcxcoin
It is worthy to note that the name
cxcoincould be changed to something else by using the--program-nameflag, but this behavior has not been tested yet.
-
cxcoinis installed by runninggo install ./cmd/cxcoin/... -
cxcoinis run to initialize the CX chain. This process involves:- Running
go run ./cmd/cxcoin/cxcoin.go --block-publisher=true --blockchain-secret-key=$SECRET_KEY.
The data directory for the publisher node is stored in
$HOME/.cxcoin/. Every time a new CX chain is initialized, its data directory is deleted first. The name of this directory can change, depending on the value of--program-name.- As this is a new blockchain, the genesis block will be created and a genesis signature is generated. This genesis signature will be different for every blockchain, even if the blockchain private and public keys are the same.
- Using the genesis signature and the secret key, a CX chain creates the first transaction in the genesis block, which is a transaction without a transaction code and with an unspent output storing the initial program state, defined by running the blockchain code.
fiber.toml's fieldgenesis_signature_stris updated automatically with the new genesis signature.- The genesis signature is printed to standard output, so the user can take note of it.
- Running
The diagram below illustrates how the different parts and processes that have been reviewed until now interact among them in order to generate the initial program state.
