Provider

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');
// or
var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
// change provider
web3.setProvider('ws://localhost:8546');
// or
web3.setProvider(new Web3.providers.WebsocketProvider('ws://localhost:8546'));
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset