Version : 1.0.0-beta.36
- Lighthouse: Lessons Learned from Testnet Collapse
- Grayscale approved to launch Ethereum Trust Fund, or push ETH prices further up
- Bitcoin fluctuates within a narrow range, waiting patiently for the market to restart
- Panic is not yet fermented, keep watching
- BTC is at the bottom, patience is the best investment
- February is another milestone, ConsenSys releases latest data report on Ethereum ecology
Web3.js API type
- Eth : Etherum blockchain related method;
- Net: the network status of the node;
- Personal: account function and sending;
- Db: Get/place the local LevelDB;
- Shh: use Whisper's P2P messaging;
First, we check if the dapp browser or the updated version of MetaMask is used to inject the Ethereum provider into the window object. If so, we use it to create our web3 object, but we also need to explicitly request access to the account using ethereum.enable().
If the ethereum object does not exist, we will check the injected web3 instance. If it exists, it means that we are using an older dapp browser (such as Mist or an older version of MetaMask). If so, we can get its provider and use it to create our web3 object.
If no web3 instance is injected, we will create a web3 object based on the local provider. (This backup is suitable for development environments, but it is not safe and not suitable for production environments.)
PS: web3.version.getNode is not recommended.
Check the user's balance
- web3.eth.getAccounts: Obtain an account from the Ethereum node. Web3.eth.accounts is deprecated.
- web3.eth.getBalance: Get the balance of the account.
- web3.utils.fromWei: Convert wei to ether, web3.fromWei is not recommended.
Transfer Ethernet from "A" to "B"
txnObject (transaction object) is the first parameter of web3.eth.sendTransaction. txnObject consists of JSON.
From:String – The address of the sending account.
To:String – the target wallet address.
Value:Number | String | BigNumber – (Optional) The number of Ethernets you want to send to the destination address.
Gas:Number | String | BigNumber – (optional, default: to be determined) The amount of gas used for the transaction (unused gas will be refunded).
gasPrice:Number | String | BigNumber – (optional, default: pending) The price of the gas in this transaction in wei. The default is the average network gas price.
Data:String – (Optional) A byte string containing the associated data for the message, or the initialization code if the contract creates a transaction.
Nonce:Number – (Optional) An integer of nonce. This allows you to override your own pending transactions that use the same nonce.
I made a web page using the above method.
- Get Ethereum node information
- Get the user's balance
- Transfer of Ethereum
You will be using MetaMask or Ganache. I recommend that you use Ganache, a personal blockchain developed for Ethereum that can be used to deploy contracts, develop applications, and run tests. If you haven't already done so, download Ganache and double-click the icon to install the app. This will generate a blockchain that runs locally on port 7545 while changing the port to 8545.
(Source: Public Number: Blockchain Research Laboratory)