4
  1. I need a default account with huge ether allocation. This I need to set up manually in genesis.json
  2. Hereafter,all accounts need to be created dynamically in java, and they should also be given some default funds.

I tried this using web3j, but its creating its own genesis block . How can I do my default setup in that genesis ?

Also, not sure whether to use smart contract here or web3j ?

Edited here

How to start geth and web3j in a private network ?

My application requires default account to be created with some default ether allocation to it. I did that using

a. "geth account new" command

b. updated genesis.json with this newly created account and allocated some balance to it

c. and then ran the init command "geth --datadir ./datadir init genesis.json"

It worked all fine.So, now I have main account with some default ether.

Now, hereafter I should be able to create new accounts dynamically. And transfer some default funds to these accounts from the main account created in the above steps.

I tried using web3j - java API , "geth --rpcapi personal,db,eth,net,web3 --rpc --testnet" But this should point to existing genesis.json and keystore . It is creating new genesis.json . How can I do this?

0

2 Answers 2

1

This tutorial cover the complete set of steps needed to develop your first smart contract in a private Ethereum node using web3j Java framework.

You can also use ganache instead of geth for development of DAPP. ganache pre-allocates 100 ethers to 10 accounts by default.

0
0

In my case, I managed to create on demand private blockchain accounts from Android Dapp with the web3j library, specially with LoadCredentials and WalletUtils. The code should be something like this: (keep in mind that this is Kotlin (Android) code, neither Java nor Geth commands, you should watch for its equivalent)

val password = "whatever_you_want" var fileName = "" val walletPath = filesDir.absolutePath var walletDir = File(walletPath) fileName = WalletUtils.generateLightNewWalletFile(password, walletDir) walletDir = File("$walletPath/$fileName") var credentials: Credentials = WalletUtils.loadCredentials(password, walletDir) 

With this you have just created one wallet account in your blockchain. The issue of giving Ether to it is more complicated, but here you are some options:

  • Transferring manually from your initial master account prefunded with a lot of Ether a little bit of it. (with Geth or Java normal transaction, i.e: Transfer.sendFunds())
  • Using a testnet like Ropsten/Rinkeby and calling faucet
  • Creating you own private customized faucet (watch my question thread about that here )

Hope it helps.

1
  • Are you sure this will create an account in the blockchain? Where is the Web3j connection part? After ran this and call "eth_accounts" I didn't see the account there Commented Aug 11, 2023 at 2:57

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.