Sorry I probably create a topic that was answered multiple times but unfortunately I couldn't find a solution. I'm trying to use RPC server of Geth to send a raw transaction. I've an address with a balance enough and a private key for that address, so I'm trying to call sendRawTransaction and it throws an error "insufficient funds for .. blabla". I have encoded the raw transaction correctly (I believe) since rlpdump shows a correct output. Please help me to find a reason what is happening
- What do I have:
- The latest version of Geth is running in the fast mode
- 99.99% synchronization
- An address with 0.5 Ether and a private key of that address
- An address of a recipient
- C++ client application that uses the RPC server of Geth
I encoded the following fields of the raw transaction according to RLP:
- Nonce (since there weren't any transactions from the address I've set it to 0x0)
- Gas price (Getting it from RPC server by appropriate method, 0x3b9aca00 Wei)
- Gas limit (Getting it from the latest block, now it is 5000)
- Address of the recipient
- Amount in Wei (I'm trying to send 0.05 Ether so it's 0xb1a2bc2ec50000 Wei)
- Empty string
Then I calculate Keccak-256 hash from that RLP encoded byte array and sign the hash by the private key by using ECDSA from OpenSSL. Afterwards I append V value to the RLP encoded byte array (V = chaindID * 2 + 35 = 37) and both R and S from calculated signature.
Then I convert the total byte array to hex string, prepend it with 0x prefix and send it to the RPC Server by JSON RPC request eth_sendRawTransaction. And finally I get the error insufficient funds. Please any ideas how to solve it, thanks in advance
P.S.: Please don't show me examples of EthereumJS usage and same libraries for other languages, I don't need any libraries, I'm just trying to understand how should it work in details
UPD: The problem was in wrong signature calculation