I'm currently using EthereumJ and I'm trying out a use case to send an amount to a specific account in my own private chain. But I'm getting this error:
Not enough cash: Require: 14000000000000001, Sender cash: 0]
I've written some basic codes and used some of the codes provided in the sample.
JsonRpcImpl jsonRpc = new JsonRpcImpl(blockchainImpl,compositeEthereumListener);
jsonRpc.setRepository(repository);
Account account = jsonRpc.addAccount("[email protected]");
try {
logger.info("Test-account:address"+account.getAddress());
String address = TypeConverter.toJsonHex(account.getAddress());
servletObject.setJsonObject("balance",account.getBalance());
servletObject.setJsonObject("address",address);
} catch (Exception e) {
e.printStackTrace();
}
Map<ByteArrayWrapper, Account> accountMap = jsonRpc.getAccounts();
logger.info("Test-accountMap:"+accountMap);
try {
sendTxAndWait(account.getAddress(), new byte[0]);
} catch (InterruptedException e) {
e.printStackTrace();
}
Here is the sendTxAndWait
Method from the Example:
private TransactionReceipt sendTxAndWait(byte[] receiveAddress, byte[] data) throws InterruptedException {
byte[] senderPrivateKey = Hex.decode("");
byte[] fromAddress = ECKey.fromPrivate(senderPrivateKey).getAddress();
BigInteger nonce = ApiServer.ethereum.getRepository().getNonce(fromAddress);
Transaction tx = new Transaction(
ByteUtil.bigIntegerToBytes(nonce),
ByteUtil.longToBytesNoLeadZeroes(ApiServer.ethereum.getGasPrice()),
ByteUtil.longToBytesNoLeadZeroes(200000),
receiveAddress,
ByteUtil.bigIntegerToBytes(BigInteger.valueOf(1)), // 1_000_000_000 gwei, 1_000_000_000_000L szabo, 1_000_000_000_000_000L finney, 1_000_000_000_000_000_000L ether
data);
tx.sign(ECKey.fromPrivate(senderPrivateKey));
logger.info("<=== Sending transaction: " + tx);
ApiServer.ethereum.submitTransaction(tx);
return waitForTx(tx.getHash());
}
Method waitForTx
from the example:
private TransactionReceipt waitForTx(byte[] txHash) throws InterruptedException {
Map<ByteArrayWrapper, TransactionReceipt> txWaiters =
Collections.synchronizedMap(new HashMap<ByteArrayWrapper, TransactionReceipt>());
ByteArrayWrapper txHashW = new ByteArrayWrapper(txHash);
txWaiters.put(txHashW, null);
long startBlock = ApiServer.ethereum.getBlockchain().getBestBlock().getNumber();
while(true) {
TransactionReceipt receipt = txWaiters.get(txHashW);
if (receipt != null) {
return receipt;
} else {
long curBlock = ApiServer.ethereum.getBlockchain().getBestBlock().getNumber();
if (curBlock > startBlock + 16) {
throw new RuntimeException("The transaction was not included during last 16 blocks: " + txHashW.toString().substring(0,8));
} else {
logger.info("Waiting for block with transaction 0x" + txHashW.toString().substring(0,8) +
" included (" + (curBlock - startBlock) + " blocks received so far) ...");
}
}
synchronized (this) {
wait(20000);
}
}
}
I was wondering if I use the account 102e61f5d8f9bc71d0ad4a084df4e65e05ce0e1c
stated in the frontier-morden.json
{
"nonce": "0x00006d6f7264656e",
"difficulty": "0x020000",
"mixhash": "0x00000000000000000000000000000000000000647572616c65787365646c6578",
"coinbase": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x",
"gasLimit": "0x2FEFD8",
"alloc": {
"0000000000000000000000000000000000000001": { "balance": "1" },
"0000000000000000000000000000000000000002": { "balance": "1" },
"0000000000000000000000000000000000000003": { "balance": "1" },
"0000000000000000000000000000000000000004": { "balance": "1" },
"102e61f5d8f9bc71d0ad4a084df4e65e05ce0e1c": { "balance": "1606938044258990275541962092341162602522202993782792835301376" }
}
}