13

this command works but yields a warning of future removal so I'd like to use new option init :

➜  ~ go-ethereum/build/bin/geth --datadir="~/testgeth/" --genesis ~/testgeth/customgenesis.json --port "30304" --networkid 6776 --rpc --rpccorsdomain="http://localhost:63342" --rpcport="8546" --minerthreads="1" --nodiscover --maxpeers=0 console

####################################################################
#                                                                  #
# --genesis is deprecated. Switch to use 'geth init /path/to/file' #
#                                                                  #
####################################################################

unfortunately the help isn't very verbose :

➜  ~ go-ethereum/build/bin/geth init --help
init [arguments...]

The init command initialises a new genesis block and definition for the network.
This is a destructive action and changes the network in which you will be
participating.

I tried that but it yields an error :

➜  ~ go-ethereum/build/bin/geth init testgeth/customgenesis.json --datadir="~/testgeth/" --port "30304" --networkid 6776 --rpc --rpccorsdomain="http://localhost:63342" --rpcport="8546" --minerthreads="1" --nodiscover --maxpeers=0 console
Incorrect Usage.

init [arguments...]

The init command initialises a new genesis block and definition for the network.
This is a destructive action and changes the network in which you will be
participating.


flag provided but not defined: -datadir
  • What version of geth are you using? – Bokky WeAreAllAssange PooBah Apr 4 '16 at 14:02
  • try geth --datadir="~/testgethnew/" make sure to run mkdir ~/testgethnew before that. – niksmac Apr 4 '16 at 14:03
  • @BokkyPooBah develop one, 1.4.0-unstable. – euri10 Apr 4 '16 at 14:19
  • @NikhilM the directories are fine, the deprecated command works perfectly, 1st one I wrote in my question in fact – euri10 Apr 4 '16 at 14:20
10

Move the --datadir "~/testgeth/" parameter before the init {customgenesis-path} parameter and it will work.

This init parameter is new, in the develop branch version 1.4.0 .

From https://github.com/ethereum/go-ethereum/blob/develop/cmd/geth/main.go#L440-L461 :

// initGenesis will initialise the given JSON format genesis file and writes it as
// the zero'd block (i.e. genesis) or will fail hard if it can't succeed.
func initGenesis(ctx *cli.Context) {
    genesisPath := ctx.Args().First()
    if len(genesisPath) == 0 {
            utils.Fatalf("must supply path to genesis JSON file")
    }

    chainDb, err := ethdb.NewLDBDatabase(filepath.Join(utils.MustMakeDataDir(ctx), "chaindata"), 0, 0)
    if err != nil {
            utils.Fatalf("could not open database: %v", err)
    }

    genesisFile, err := os.Open(genesisPath)
    if err != nil {
            utils.Fatalf("failed to read genesis file: %v", err)
    }

    block, err := core.WriteGenesisBlock(chainDb, genesisFile)
    if err != nil {
            utils.Fatalf("failed to write genesis block: %v", err)
    }
    glog.V(logger.Info).Infof("successfully wrote genesis block and/or chain rule set: %x", block.Hash())
}

From https://github.com/ethereum/go-ethereum/blob/develop/cmd/utils/flags.go#L387-L399 :

// MustMakeDataDir retrieves the currently requested data directory, terminating
// if none (or the empty string) is specified. If the node is starting a testnet,
// the a subdirectory of the specified datadir will be used.
func MustMakeDataDir(ctx *cli.Context) string {
    if path := ctx.GlobalString(DataDirFlag.Name); path != "" {
            if ctx.GlobalBool(TestNetFlag.Name) {
                    return filepath.Join(path, "/testnet")
            }
            return path
    }
    Fatalf("Cannot determine default data directory, please set manually (--datadir)")
    return ""
}



Update 20/07/2016

From geth Command Line Options - Init:

Init

With the init command it is possible to create a chain with a custom genesis block and chain configuration (currently only the homestead transition block can be configured). It respects the --datadir argument and accepts a JSON file describing the chain configuration.

geth --datadir <some/location/where/to/create/chain> init genesis.json

Example genesis.json file:

{
    "config": {
            "homesteadBlock": "10"
    },
    "nonce": "0",
    "difficulty": "0x20000",
    "mixhash": "0x00000000000000000000000000000000000000647572616c65787365646c6578",
    "coinbase": "0x0000000000000000000000000000000000000000",
    "timestamp": "0x00",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "extraData": "0x",
    "gasLimit": "0x2FEFD8",
    "alloc": {}
}

To use the created chain start geth with:

geth --datadir <some/location/where/to/create/chain>
  • go-ethereum/build/bin/geth init testgeth/customgenesis.json --datadir ~/testgeth with or without quotes around the datadir directory yields the same error: flag provided but not defined: -datadir – euri10 Apr 4 '16 at 14:53
  • go-ethereum/build/bin/geth init testgeth/customgenesis.json datadir="~/testgeth" is a little bit better : I0404 16:54:55.024842 ethdb/database.go:82] Alloted 16MB cache and 16 file handles to /home/lotso/.ethereum/chaindata Fatal: could not open database: resource temporarily unavailable seems like a bug handling arguments in the init command to me – euri10 Apr 4 '16 at 14:55
  • 2
    use the --datadir '{directory}' before the init parameter and it works. – Bokky WeAreAllAssange PooBah Apr 4 '16 at 14:57
  • mmmm you're right the --datadir and other -- args apply to geth ! thanks – euri10 Apr 4 '16 at 14:59
  • 2
    As a side note: Be very careful running init. If you forget to set the datadir you will overwrite you existing chaindata! – dbryson Jun 7 '16 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.