我目前正在使用EthereumJ,我正在试用一个用例将金额发送到我自己的私人连锁店中的一个特定帐户。但我发现了一个错误:
现金不足:要求: 14000000000000001,发件人现金: 0]
我编写了一些基本代码,并使用了示例中提供的一些代码。
JsonRpcImpl jsonRpc = new JsonRpcImpl(blockchainImpl,compositeEthereumListener);
jsonRpc.setRepository(repository);
Account account = jsonRpc.addAccount("ngzhongqin@gmail.com");
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();
}下面是示例中的sendTxAndWait方法:
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());
}示例中的waitForTx方法:
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);
}
}
}我想知道我是否使用了在边境-morden.json中所述的帐户102e61f5d8f9bc71d0ad4a084df4e65e05ce0e1c。
{
"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" }
}
}发布于 2017-11-07 15:27:07
尝试将事务“值”更改为2100000000000000000L。将气体限制暂时提高为3_000_000。如果您试图创建一个契约或写入一个非payable的契约函数,那么请确保您的'value‘字段是0。确保您的.conf文件指向正确的成因块,以便它注册资金。
我的创世区和你的相似:
"alloc": { "31e2e1ed11951c7091dfba62cd4b7145e947219c": { "balance": "1606938044258990275541962092341162602522202993782792835301376" } }
在我的.conf文件中引用为:genesis = sample-genesis.json。
我会再次检查一下,你是否在用正确的密钥签名,这个密钥与你已经装上资金的账户相对应。我已经发现,通过REST服务,Ethereumj作为一个客户可以更好地工作。我还没有使用它的JsonRpc功能。我知道Web3j在这方面有很好的服务。
https://ethereum.stackexchange.com/questions/9551
复制相似问题