Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect to remote geth ip rpc #1

Merged
merged 27 commits into from
Mar 7, 2018
Merged

Conversation

thinkocapo
Copy link
Owner

@thinkocapo thinkocapo commented Feb 26, 2018

Send Raw Transaction

  1. Are data and chainId needed? MEW generates tx json and includes them but Decyphermedia's tutorial series omits them
  2. Gas Price - use what's given by web3.eth.getGasPrice() because tutorial videos may be out of date. So ignore 21000?
  3. Gas Limit - use what's given by web3.eth.getBlock("latest") because tutorial videos may be out of date.
  4. Value - hex(wei) for now because .toWei(value, 'ether') throws an error due to data type and wants value.toString(), but don't want to risk this losing me money.
  5. Nonce - use web3.getTransactionCount(address), but why is it different than MEW's tx json nonce?
      console.log({
        nonce: txCount,
        gasPrice: gasPrice,
        gasLimit: gasLimit,
        to: eosContractAddress,
        value: value,
        "data":"",
        "chainId": chain
      })
      
      const rawTx = {
        nonce: hex(txCount),
        gasPrice : hex(gasPrice), 
        gasLimit: hex(300000),
        to: eosContractAddress,
        value: hex(web3.utils.toWei(value.toString(),'ether')), // *TODO* hard-code the Wei the first time
        "data":"",
        "chainId": chain
      }

Calcualte Gas Price from Ether

Gas to ether is determined by the miners
Go to ethstats.net
dynamic exchange rate of ether to gas....
how much gwei for that gasPrice...
21000 gas to execute a transaction....

  1. netstat says current gasPrice is 20gwei
web3.fromWei(web3.toWei(20, "gwei") * 21000, "ether")

Notes

--rpc
Good chance that Unhandled rejection Error: Invalid JSON RPC response: "" means need pass the --rpc flag to accept inbound RPC connection calls, which are sent by Web3.js, as well as the geth console if you run geth attach. Discussion: trufflesuite/truffle#492

geth --rpc --rpccorsdomain "http://localhost:3000"
is for running a geth node locally and permitting the webapp you're running on :3000 to make connections to geth.

geth --rpc --rpccorsdomain "http://191.156.25.51:3000"
Is for running geth locally locally and permitting connection requests from IP 191.156.25.51 which is someone not in your physicall location (i.e. remote), and they're sending their requests from a node.js program running on their local :3000 port.

Geth node accepts external connections on 30303? I read something about. Have remote guy try connecting to port 30303 if 8545 isn't working. Need better understand the 8545 vs 30303 usage.

Original port provided to me was for SSH, which is what I requested. But now I'm hitting 8545 so I can hit the geth node directly as opposed to ssh remote connection.

Avoid committing IP addresses to source code. Instead, share a .env file. App config is updated in this PR to use this.

Todo

  1. Confirm geth running on 8545. This is the default, as long as an alternative wasn't used via --rpcport <portNumber>
  2. Confirm the URL provided is still correct: http://[hidden]:8545
  3. Re-run geth program with argument --rpc and have remote IP guy re-run getBlock script for getBlock(5000000). This allows the node to accept connections from other programs on the same localhost.
  4. Re-run geth program with --rpc --rpccorsdomain "http://191.156.25.51:3000" as stated above in Notes, then have remote guy from that IP re-run getBlock script. Ask remote guy what their IP address is and use that. --rpccorsdomain allows the node to accept connections from other programs on a different IP altogther.

Reference

JSON-RPC API
How-to-allow-remote-connections-to-ethereum-node?
How-can-i-expose-geths-rpc-server-to-external-connections?

@thinkocapo
Copy link
Owner Author

First Test Trial:

======= txSignedSerializedHx ======= f86c1085037e11d600837a211094d8479d6c2b49276f8dc750efbe4c3bf8b84d073e870aa87bee5380008025a07fb5e42c719e1686c1d79e9c2ec6e07d08260545b21427458db00c2a7800259ba021aec7221450512a462fc07ad8edec1f9fa6fab4f9b55ca3b53acd9834e9768b
Unhandled rejection Error: Returned error: Insufficient funds. The account you tried to send transaction from does not have enough funds. Required 123057840000000000 and got: 0.
    at Object.ErrorResponse (/Users/WillsHome/Projects/hash-tronic/node_modules/web3-core-helpers/src/errors.js:29:16)
    at /Users/WillsHome/Projects/hash-tronic/node_modules/web3-core-requestmanager/src/index.js:137:36
    at XMLHttpRequest.request.onreadystatechange (/Users/WillsHome/Projects/hash-tronic/node_modules/web3-providers-http/src/index.js:77:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/WillsHome/Projects/hash-tronic/node_modules/xhr2/lib/xhr2.js:64:18)
    at XMLHttpRequest._setReadyState (/Users/WillsHome/Projects/hash-tronic/node_modules/xhr2/lib/xhr2.js:354:12)
    at XMLHttpRequest._onHttpResponseEnd (/Users/WillsHome/Projects/hash-tronic/node_modules/xhr2/lib/xhr2.js:509:12)
    at IncomingMessage.<anonymous> (/Users/WillsHome/Projects/hash-tronic/node_modules/xhr2/lib/xhr2.js:469:24)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:188:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)

@thinkocapo
Copy link
Owner Author

First Trial complete

@thinkocapo thinkocapo merged commit f394ae3 into dev Mar 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant