December 2018
Intermediate to advanced
222 pages
6h 6m
English
A provider abstracts a connection that talks to the Ethereum blockchain. It will issue queries and send transactions to the blockchain. web3 provides JsonRpcProvider and IpcProvider, which allow you to connect to a local or remote Ethereum node, including Mainnet, Ropsten testnet, Kovan testnet, Rinkeby testnet, and custom remote procedure call (RPC), like Ganache. Below is the code snippet to show how we can use web3 API to connect an Ethereum node.
var Web3 = require('web3');var web3 = new Web3('http://localhost:8545');// orvar web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));// change providerweb3.setProvider('ws://localhost:8546');// orweb3.setProvider(new Web3.providers.WebsocketProvider('ws://localhost:8546')); ...Read now
Unlock full access