2

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" }
    }
}

1 Answer 1

0

Try changing the transaction 'value' to 2100000000000000000L. Increase the gas limit for the time being to be 3_000_000. If you are attempting to create a contract or write to a contract function that is not payable then make sure you the 'value' field is 0. Ensure your .conf file is pointing to the correct genesis block so that it registers the funds.

My genesis block is similar to yours:

"alloc": { "31e2e1ed11951c7091dfba62cd4b7145e947219c": { "balance": "1606938044258990275541962092341162602522202993782792835301376" } }

Reference in my .conf file as : genesis = sample-genesis.json.

I'd double check that you're signing with the correct key corresponding to the account that you've loaded with funds. I've found Ethereumj to work better as a client via a REST service. I've yet to use it's JsonRpc functionality. I know Web3j has a good service for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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