Loading...
Extension object from web3 will add rpc methods into current web3 module of the dapp. There are many rpc calls that are not added as a method in web3 but they provide extension object with which we can add required rpc methods/calls into our working web3 module or instance.
Let's add get balance and gas price super RPC methods in our web3 module
const Web3 = require("web3");
Web3.extend({
property: 'myModule',
methods: [{
name: 'getBalance',
call: 'eth_getBalance',
params: 2,
inputFormatter: [web3.extend.formatters.inputAddressFormatter,
web3.extend.formatters.inputDefaultBlockNumberFormatter]
},{
name: 'getGasPriceSuperFunction',
call: 'eth_gasPriceSuper',
params: 2,
inputFormatter: [null, web3.utils.numberToHex]
}]
});