Hashtronic was conceived as a trading arbitrage bot that sends ether to the EOS Crowdsale Smart Contract in exchange for EOS tokens (ERC-20), which then get re-sold on an exchange for even more ether than you started with.
Currently this repo has code for sending ether from one address to another on the mainnet, the real public ethereum blockchain. You can send to either an account address or to a contract address (a.k.a. externally owned account)like EOS. Account Address vs Contract Address. We will use web3.js to do that.
wei - web3 caluclation <BN: aa87bee538000>
wei - etherconverter.online calculation 3000000000000000
# of ethere the gasPrice costs - web3 0.000063
# of ether the gasPrice costs - tutorial 0.00042
INPUTS TO RAW TRANSACTION
{ nonce: 17,
gasPrice: { [String: '3000000000'] s: 1, e: 9, c: [ 3000000000 ] },
gasLimit: 7999992,
to: '0xD8479D6c2b49276F8Dc750EFbe4C3BF8b84D073e',
value: 0.003,
chainId: '1',
data: '' }
RAW TRANSACTION
{ nonce: '0x11',
gas: '0x5208',
gasPrice: '0x2540be400',
to: '0xD8479D6c2b49276F8Dc750EFbe4C3BF8b84D073e',
value: '0x226161383762656535333830303022' }
=== EARLY RETURN - DONE - DO NOT RUN web3.eth.sendRawTransaction ===
There are instructions in /docs/geth.md on how to run an ethereum node using geth, the command line interface for running a full ethereum node implemented in Go. Additional notes and links in /docs/tools.md on all tools involved.
But for simplicity I've chosen to connect to MyEtherWallet's geth node.
IMPORTANT DEV TIP:
- web3 is the javascript client lib for connecting to your ethereum node.
- Hash-tronic uses: web3 v1.0.0-beta.30
- not to be confused with: web3 v0.2x.x
- The v0.2x.x methodology (syntax, methods) is what a lot of literature (e.g. stackoverflow, github) references
- Some developers use v1.0.0 in production, many are still using v0.2x.x
git clone https://github.com/thinkocapo/hash-tronic.git
- Select which ethereum node (geth) you'll connect to in index.js#L15. I recommend MyEtherWallet's node but you have other options in /eth-nodes.js. See /docs/geth.md for instructions on how to run your own.
// tells web3 which ethereum node it will make calls to
let web3 = new Web3(new Web3.providers.HttpProvider(node))
- Paste your private key in a new
/.env
file asprivateKey=[private_key]
. The .gitignore file ensures this never get pushed to Github. This privateKey will be used here to verify your ownership of the account address being used to send ether. See 'Raw Transaction' section for more technical details. npm start sendEther 0.003
The recipient will default to whatever you put asreciepientAddress=[paste_address]
in your.env
. Or specify it as a 3rd argument tonpm start
. 0.003 ether is ~$2.00 worth of ether as of 03/12/18.- Make sure all loggers executed, the output looks good, and there are no errors.
- Remove the early
return
statement in the sendEther method. Re-runnpm start sendEther 0.003
so the transaction will go through - You'll see a resulting Transaction Hash logged as output. Visit the following links at Etherscan Block Explorer to see your transaction's data and status, and view updated balances:
https://etherscan.io/tx/[transactionHash]
https://etherscan.io/address/[fromAddress]
https://etherscan.io/address/[recipientAddress]
- If your $ didn't go through or its stuck for days on pending, there is no un-do button.
Raw Transaction
- You sign the transaction object using your privateKey, before sending it to the ethereum node. This generates the raw bytes. Basically a raw transaction is a machine representation of a transaction, with the signature attached to it.
- You could take this signed transaction object, and email it to a friend and have them send it to the ethereum node via web3.js, if you wanted to.
transaction.sign(privateKey)
web3.eth.sendSignedTransaction('0x' + transaction.toString('hex'))
- Raw bytes are required if you're connecting to a node hosted by MyEtherWallet/Infura/Etherscan, which do not not handle private keys but deal only with signed transactions.
- If you're connecting to a local instance of geth/ethereum (localhost:8545), then you can manage your own privateKeys (i.e. import them into geth) so you don't have to 'sign' the transaction everytime.
- Difference Between Transactions and Raw Transactions - ethereum.stackexchange
- What Is A Raw Transaction Used For - ethereum.stackexchange
VS.
Transaction
- You already unlocked the account at that node, the node can handle privateKeys.
web3.eth.sendTransaction({
from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe',
to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe',
value: '1000000000000000'
})
// Notice - no privateKey needed, because it was already imported and geth can access it at web3.accounts[0]
Step 1 is the sendEther method documented above.
- Send ether from your account address to the to E0S contract address.
- Claim your E0S tokens the next day by calling the eos contract's claimAll() method, using your account address.
- Send your E0S tokens to a crypto trading exchange by hitting their API.
- Perform a trade of E0S-to-ETH using the exchange's API.
- Send this ether back to your account address.
- The quantity of this ETH is greater than what you started with in Step 1.
- Repeat from Step 1.