Send ether
send the ether from light node to Android node
- light node console
> eth.sendTransaction({
"from": "0x52ea0215068f436f837788686aa4b25de1a98f07",
"to": "0xEDA1370B372a909AAEC04E56ac395F1FAa5B585d",
"gas": "30000",
"value": web3.toWei(8, "ether")
})
INFO [10-02|16:22:20] Submitted transaction fullhash=0xecd573d19072d344b9bde5d90e7da56d08d9b4a23cb1d97a49e1b4c2e2be64f4 recipient=0xEDA1370B372a909AAEC04E56ac395F1FAa5B585d
"0xecd573d19072d344b9bde5d90e7da56d08d9b4a23cb1d97a49e1b4c2e2be64f4"
> txpool.status
{
pending: 1,
queued: 0
}
- server node console
> txpool.status
{
pending: 1,
queued: 0
}
> eth.getTransaction("0xecd573d19072d344b9bde5d90e7da56d08d9b4a23cb1d97a49e1b4c2e2be64f4")
{
blockHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
blockNumber: null,
from: "0x52ea0215068f436f837788686aa4b25de1a98f07",
gas: 30000,
gasPrice: 18000000000,
hash: "0xecd573d19072d344b9bde5d90e7da56d08d9b4a23cb1d97a49e1b4c2e2be64f4",
input: "0x",
nonce: 4,
r: "0xa4454b17b43f4ffdcdbce9064424b9c36663c1b4281bcf6391aad009cd8b214",
s: "0x408f73adfb34e66f2decc692a5576c431a1abc3a5824e43db3d81883e6bcf081",
to: "0xeda1370b372a909aaec04e56ac395f1faa5b585d",
transactionIndex: 0,
v: "0x1bc0d",
value: 8000000000000000000
}
> miner.start()
INFO [10-02|16:23:36] Transaction pool price threshold updated price=18000000000
INFO [10-02|16:23:36] Starting mining operation
null
> INFO [10-02|16:23:36] Commit new mining work number=133 txs=1 uncles=0 elapsed=1.447ms
INFO [10-02|16:23:36] 🔗 block reached canonical chain number=127 hash=89e346…c8772c
INFO [10-02|16:23:36] Successfully sealed new block number=133 hash=227257…3c4f8f
INFO [10-02|16:23:36] 🔨 mined potential block number=133 hash=227257…3c4f8f
> txpool.status
{
pending: 0,
queued: 0
}
- miner2 node console
> txpool.status
{
pending: 1,
queued: 0
}
> eth.getTransaction("0xecd573d19072d344b9bde5d90e7da56d08d9b4a23cb1d97a49e1b4c2e2be64f4")
{
blockHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
blockNumber: null,
from: "0x52ea0215068f436f837788686aa4b25de1a98f07",
gas: 30000,
gasPrice: 18000000000,
hash: "0xecd573d19072d344b9bde5d90e7da56d08d9b4a23cb1d97a49e1b4c2e2be64f4",
input: "0x",
nonce: 4,
r: "0xa4454b17b43f4ffdcdbce9064424b9c36663c1b4281bcf6391aad009cd8b214",
s: "0x408f73adfb34e66f2decc692a5576c431a1abc3a5824e43db3d81883e6bcf081",
to: "0xeda1370b372a909aaec04e56ac395f1faa5b585d",
transactionIndex: 0,
v: "0x1bc0d",
value: 8000000000000000000
}
> INFO [10-02|16:23:36] Imported new chain segment blocks=1 txs=1 mgas=0.021 elapsed=1.783ms mgasps=11.776 number=133 hash=227257…3c4f8f
> miner.start()
INFO [10-02|16:23:44] Transaction pool price threshold updated price=18000000000
INFO [10-02|16:23:44] Starting mining operation
null
> INFO [10-02|16:23:44] Commit new mining work number=134 txs=0 uncles=0 elapsed=91.084µs
> txpool.status
{
pending: 0,
queued: 0
}
> eth.getBalance("0xEDA1370B372a909AAEC04E56ac395F1FAa5B585d")
8000000000000000000
- LogCat
E/GoLog: INFO [10-02|08:23:36] Block synchronisation started
E/GoLog: INFO [10-02|08:23:36] Imported new block headers count=4 elapsed=154.772ms number=133 hash=227257…3c4f8f ignored=1
D/main: #130: 0x2f7b424c
D/main: peers amount 1; Geth/server/v1.7.0-stable-6c6c7b2a/darwin-amd64/go1.7.1; 540e892d76e86b3221aed4858613d7a9b96a1199db4c00901803dfc4abb59e1be359bd33281b91abb126aeb048c79a0720f80a5688c07b3ee4e16fcd5f44a83b; 192.168.200.207:30303
D/main: balance of android node 0xEDA1370B372a909AAEC04E56ac395F1FAa5B585d is 8000000000000000000
D/main: balance of server node 0x726794b16f6c5b0be0b78d7713a876ed3da8be1a is 1000378000000000000
D/main: balance of miner2 node 0xc077f8420d5b6c125897d9c5e21293ff6f77855c is 8447878073709551616
D/main: balance of light node 0x52ea0215068f436f837788686aa4b25de1a98f07 is 998488000000000000
The account on Android node has 8 ether now.
send the ether from Android node to server node
Send 0.999622 ether from Android node to server node.
public class MainActivity extends AppCompatActivity {
private boolean isNotSend = true;
private void connect2PrivateChain() throws Exception {
createKeyStore(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + "ETH" + "/privatechain/keystore").getPath());
Accounts accounts = keyStore.getAccounts();
account = accounts.get(0);
final Context ctx = new Context();
NodeConfig nodeConfig = Geth.newNodeConfig();
nodeConfig.setEthereumNetworkID(PRIVATE_CHAIN_NETWORK_ID);
nodeConfig.setEthereumGenesis(PrivateChain.genesis);
nodeConfig.setEthereumDatabaseCache(512);
nodeConfig.setMaxPeers(10);
nodeConfig.setWhisperEnabled(true);
nodeConfig.setEthereumEnabled(true);
final Node node = Geth.newNode(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + "ETH" + "/privatechain").getPath(), nodeConfig);
try {
node.start();
NodeInfo info = node.getNodeInfo();
Log.d("main", "name is " + info.getName());
Log.d("main", "address is " + info.getListenerAddress());
Log.d("main", "protocols is " + info.getProtocols());
Log.d("main", "ID is " + info.getID());
Log.d("main", "ListenerPort is " + info.getListenerPort());
Log.d("main", "DiscoveryPort is " + info.getDiscoveryPort());
Log.d("main", "IP is " + info.getIP());
Log.d("main", "enode is " + info.getEnode());
final EthereumClient ec = node.getEthereumClient();
try {
Log.d("main", "Latest block: " + ec.getBlockByNumber(ctx, -1).getNumber() + ", syncing");
} catch (Exception e) {
e.printStackTrace();
}
NewHeadHandler handler = new NewHeadHandler() {
@Override
public void onError(String error) {
Log.d("main", "NewHeadHandler: " + error);
}
@Override
public void onNewHead(final Header header) {
try {
Log.d("main", "#" + header.getNumber() + ": " + header.getHash().getHex().substring(0, 10));
PeerInfo peerInfo = node.getPeersInfo().get(0);
Log.d("main", "peers amount " + node.getPeersInfo().size() + "; " + peerInfo.getName() + "; " + peerInfo.getID() + "; " + peerInfo.getRemoteAddress());
Log.d("main", "balance of android node " + account.getAddress().getHex() + " is " + ec.getBalanceAt(ctx, account.getAddress(), -1).getInt64());
Log.d("main", "balance of server node 0x726794b16f6c5b0be0b78d7713a876ed3da8be1a is " + ec.getBalanceAt(ctx, new Address("0x726794b16f6c5b0be0b78d7713a876ed3da8be1a"), -1).getInt64());
Log.d("main", "balance of miner2 node 0xc077f8420d5b6c125897d9c5e21293ff6f77855c is " + ec.getBalanceAt(ctx, new Address("0xc077f8420d5b6c125897d9c5e21293ff6f77855c"), -1).getInt64());
Log.d("main", "balance of light node 0x52ea0215068f436f837788686aa4b25de1a98f07 is " + ec.getBalanceAt(ctx, new Address("0x52ea0215068f436f837788686aa4b25de1a98f07"), -1).getInt64());
if (isNotSend) {
try {
int nonce = 0;
BigInt amount = new BigInt(999622000000000000L);
BigInt gasLimit = new BigInt(30000L);
BigInt gasPrice = new BigInt(18000000000L);
Transaction tx = Geth.newTransaction(
nonce,
new Address("0x726794b16f6c5b0be0b78d7713a876ed3da8be1a"),
amount,
gasLimit,
gasPrice,
null
);
BigInt chain = new BigInt(PRIVATE_CHAIN_NETWORK_ID);
keyStore.unlock(account, "a1234567");
Transaction signed = keyStore.signTx(account, tx, chain);
Log.d("main", "tx hash " + signed.getHash().getHex() + " signed hash " + signed.getSigHash().getHex());
Log.d("main", "gas " + signed.getGas() + "; gasPrice " + signed.getGasPrice().getInt64());
ec.sendTransaction(ctx, signed);
isNotSend = false;
keyStore.lock(account.getAddress());
Transaction transaction = ec.getTransactionByHash(ctx, signed.getHash());
Log.d("main", "check tx: gas " + transaction.getGas() + "gasPrice " + transaction.getGasPrice().getInt64() + "; to " + transaction.getTo().getHex());
Log.d("main", "check tx: pending balance is " + ec.getPendingBalanceAt(ctx, transaction.getTo()));
} catch (Exception e) {
Log.e("main", "transaction: " + e.toString());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
ec.subscribeNewHead(ctx, handler, 16);
} catch (Exception e) {
e.printStackTrace();
}
}
}
- LogCat
E/GoLog: INFO [10-02|08:41:38] Block synchronisation started
E/GoLog: INFO [10-02|08:41:38] Imported new block headers count=1 elapsed=184.933ms number=163 hash=c7839a…451829 ignored=2
D/main: #163: 0xc7839a92
D/main: peers amount 1; Geth/server/v1.7.0-stable-6c6c7b2a/darwin-amd64/go1.7.1; 540e892d76e86b3221aed4858613d7a9b96a1199db4c00901803dfc4abb59e1be359bd33281b91abb126aeb048c79a0720f80a5688c07b3ee4e16fcd5f44a83b; 192.168.200.207:30303
D/main: balance of android node 0xEDA1370B372a909AAEC04E56ac395F1FAa5B585d is 8000000000000000000
D/main: balance of server node 0x726794b16f6c5b0be0b78d7713a876ed3da8be1a is 1000378000000000000
D/main: balance of miner2 node 0xc077f8420d5b6c125897d9c5e21293ff6f77855c is 8447878073709551616
D/main: balance of light node 0x52ea0215068f436f837788686aa4b25de1a98f07 is 998488000000000000
D/main: tx hash 0xe3833f0fa82292d4922fa726f83ff642422ff94d04c8102b91deaa8e3ab2f14b signed hash 0xf36cf18ca38ef53cca26a2e862e78a5b2ef7781dc2241a3e9d95a2a0a8f13c2c
D/main: gas 30000; gasPrice 18000000000
E/GoLog: INFO [10-02|08:41:38] Submitted transaction fullhash=0xe3833f0fa82292d4922fa726f83ff642422ff94d04c8102b91deaa8e3ab2f14b recipient=0x726794b16F6c5B0Be0B78D7713a876eD3DA8BE1a
D/main: check tx: gas 30000gasPrice 18000000000; to 0x726794b16F6c5B0Be0B78D7713a876eD3DA8BE1a
D/main: check tx: pending balance is 1000378000000000000
E/GoLog: INFO [10-02|08:42:27] Imported new block headers count=2 elapsed=4.442ms number=165 hash=166734…f2a73f ignored=0
D/main: #164: 0x20a21471
D/main: peers amount 1; Geth/server/v1.7.0-stable-6c6c7b2a/darwin-amd64/go1.7.1; 540e892d76e86b3221aed4858613d7a9b96a1199db4c00901803dfc4abb59e1be359bd33281b91abb126aeb048c79a0720f80a5688c07b3ee4e16fcd5f44a83b; 192.168.200.207:30303
D/main: balance of android node 0xEDA1370B372a909AAEC04E56ac395F1FAa5B585d is 7000000000000000000
D/main: balance of server node 0x726794b16f6c5b0be0b78d7713a876ed3da8be1a is 2000000000000000000
D/main: balance of miner2 node 0xc077f8420d5b6c125897d9c5e21293ff6f77855c is 8448256073709551616
D/main: balance of light node 0x52ea0215068f436f837788686aa4b25de1a98f07 is 998488000000000000
- server node console
> miner.start()
INFO [10-02|16:41:38] Transaction pool price threshold updated price=18000000000
INFO [10-02|16:41:38] Starting mining operation
null
> INFO [10-02|16:41:38] Commit new mining work number=163 txs=0 uncles=0 elapsed=77.925µs
INFO [10-02|16:41:38] 🔗 block reached canonical chain number=157 hash=6120f3…785a8c
INFO [10-02|16:41:38] Successfully sealed new block number=163 hash=c7839a…451829
INFO [10-02|16:41:38] 🔨 mined potential block number=163 hash=c7839a…451829
INFO [10-02|16:41:38] Commit new mining work number=164 txs=0 uncles=0 elapsed=423.884µs
INFO [10-02|16:41:38] Signed recently, must wait for others
> txpool.status
{
pending: 1,
queued: 0
}
> eth.getTransaction("0xe3833f0fa82292d4922fa726f83ff642422ff94d04c8102b91deaa8e3ab2f14b")
{
blockHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
blockNumber: null,
from: "0xeda1370b372a909aaec04e56ac395f1faa5b585d",
gas: 30000,
gasPrice: 18000000000,
hash: "0xe3833f0fa82292d4922fa726f83ff642422ff94d04c8102b91deaa8e3ab2f14b",
input: "0x",
nonce: 0,
r: "0xf547078d247d0b139937d58599141de33384956400dc72dab1635e9c8cf3aea7",
s: "0x576435f67c33db1a4a88698ba159413a23ae0f6a38d41cf9b9918134e9b72f8f",
to: "0x726794b16f6c5b0be0b78d7713a876ed3da8be1a",
transactionIndex: 0,
v: "0x1bc0d",
value: 999622000000000000
}
> INFO [10-02|16:42:24] Imported new chain segment blocks=1 txs=1 mgas=0.021 elapsed=829.174µs mgasps=25.326 number=164 hash=20a214…da11db
> eth.getTransaction("0xe3833f0fa82292d4922fa726f83ff642422ff94d04c8102b91deaa8e3ab2f14b")
{
blockHash: "0x20a214714784e6bd9dbac434103446c4d36939f5401e4b5d0b4ed94034da11db",
blockNumber: 164,
from: "0xeda1370b372a909aaec04e56ac395f1faa5b585d",
gas: 30000,
gasPrice: 18000000000,
hash: "0xe3833f0fa82292d4922fa726f83ff642422ff94d04c8102b91deaa8e3ab2f14b",
input: "0x",
nonce: 0,
r: "0xf547078d247d0b139937d58599141de33384956400dc72dab1635e9c8cf3aea7",
s: "0x576435f67c33db1a4a88698ba159413a23ae0f6a38d41cf9b9918134e9b72f8f",
to: "0x726794b16f6c5b0be0b78d7713a876ed3da8be1a",
transactionIndex: 0,
v: "0x1bc0d",
value: 999622000000000000
}
> eth.getBlock(164)
{
difficulty: 1,
extraData: "0xd883010700846765746887676f312e372e318664617277696e000000000000008519dc9e903ae08e118f913be4a09e616272386d178ce68a598dceaa6a0aadb612d86c6970bfd7ff24f0e8436170102e34bb7f0f5023f3fedd4626c4fb00bf1300",
gasLimit: 4712388,
gasUsed: 21000,
hash: "0x20a214714784e6bd9dbac434103446c4d36939f5401e4b5d0b4ed94034da11db",
logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
miner: "0x0000000000000000000000000000000000000000",
mixHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
nonce: "0x0000000000000000",
number: 164,
parentHash: "0xc7839a928c9dff03b9b8ba6870afc4dcf883424f1841987c22033f4c16451829",
receiptsRoot: "0xb77033623d2315c5b88972ac58516a89c1405584b53a9d0dbd9f9165d9ce1e51",
sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
size: 723,
stateRoot: "0x7c455ce1b380e2540e1ca07fc6e9b3ec416ab0462079867f53051080e7c9ade1",
timestamp: 1506933744,
totalDifficulty: 166,
transactions: ["0xe3833f0fa82292d4922fa726f83ff642422ff94d04c8102b91deaa8e3ab2f14b"],
transactionsRoot: "0x9b07a43f9482d943ebe081d05f946546e92f8c2a3dec80978355ae6ed25589fb",
uncles: []
}
- miner2 node console
> miner.start()
INFO [10-02|16:42:24] Transaction pool price threshold updated price=18000000000
INFO [10-02|16:42:24] Starting mining operation
null
> INFO [10-02|16:42:24] Commit new mining work number=164 txs=1 uncles=0 elapsed=1.533ms
INFO [10-02|16:42:24] 🔗 block reached canonical chain number=158 hash=a5bcc2…a09c69
INFO [10-02|16:42:24] Successfully sealed new block number=164 hash=20a214…da11db
INFO [10-02|16:42:24] 🔨 mined potential block number=164 hash=20a214…da11db
> eth.getBalance("0x726794b16f6c5b0be0b78d7713a876ed3da8be1a")
2000000000000000000
> eth.getBalance("0xEDA1370B372a909AAEC04E56ac395F1FAa5B585d")
7000000000000000000
nonce issue
My transaction ever entry to transaction queue. It is looks like below when use console output.
> txpool.status
{
pending: 0,
queued: 1
}
When use Geth.newTransaction()
, the nonce
(first parameter) should be sequence.
What is the difference between a pending transaction and a queued transaction?
always in pending issue
When I send transaction from Android node, the other miner nodes in private chain should has the pending transaction in txpool
. And I can check the information with eth.getTransaction()
on their console. If not, I can say the reason is too low gasPrice
.
exceeds block gas limit or intrinsic gas too low issue
I change the value of gasLimit
and gasPrice
to fix these problems.
Can't send transaction — “Exceeds block gas limit” or “Intrinsic gas too low”