Show how to connect on a Ethereum network using web3. Demonstrate how to create a transaction with ethereumjs-tx. We'll too sign the transaction and send it to the network.
To see how is the Ethereum network you can access https://ethstats.net/ But if you wanna see how it works in a development environment, you can use the web3 library. We see this use on the src/ethStatistics.js
On the Ethereum network we have two types of transactions:
- Message calls
- Contract creation
Let's go over transaction's fields in a little more detail.
Is a transaction count from the sender's account. Every transaction that occurs needs to have a unique incrementing nonce. The first transaction you send from your account will have a nonce of zero.
Is the price the sender is willing to pay per unit of a gas. Is a similar concept like miner fees in the Bitcoin. Ethereum uses gas to determine the reward miners received for executing contracts. The price set here is the incentive miners have to mine new transactions.
Specifies the maximum number of gas that the contract can spend. This is useful for a few reasons that we'll go over it in a later section.
Specifies the recipient's address.
The amount of Ether you want send is shown in the value field.
Information used to record creation and execution of smart contrats.
At this code I'll make a transaction between two accounts. To do that, there's a few main things that need happen.
First I need to bring in the dependencies and set up my connection between Web3 and Ganache.
Makes possible the communication between an app and the ethereum blockchain.
It's a tool that allow us to use a local ethereum blockchain that preset 10 accounts with 100 ether each one.
We use this library to create a new transaction.
Go to the code to undestand better src/index.js