Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ethers-providers

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ethers-providers - npm Package Compare versions

Comparing version 2.1.4 to 2.1.5

networks.json

46

etherscan-provider.js

@@ -14,2 +14,10 @@ 'use strict';

// @TODO: Add this to utils; lots of things need this now
function stripHexZeros(value) {
while (value.length > 3 && value.substring(0, 3) === '0x0') {
value = '0x' + value.substring(3);
}
return value;
}
function getTransactionString(transaction) {

@@ -19,3 +27,7 @@ var result = [];

if (transaction[key] == null) { continue; }
result.push(key + '=' + utils.hexlify(transaction[key]));
var value = utils.hexlify(transaction[key]);
if ({ gasLimit: true, gasPrice: true, nonce: true, value: true }[key]) {
value = stripHexZeros(value);
}
result.push(key + '=' + value);
}

@@ -25,5 +37,24 @@ return result.join('&');

function EtherscanProvider(testnet, apiKey) {
Provider.call(this, testnet);
function EtherscanProvider(network, apiKey) {
Provider.call(this, network);
var baseUrl = null;
switch(this.name) {
case 'homestead':
baseUrl = 'https://api.etherscan.io';
break;
case 'ropsten':
baseUrl = 'https://ropsten.etherscan.io';
break;
case 'rinkeby':
baseUrl = 'https://rinkeby.etherscan.io';
break;
case 'kovan':
baseUrl = 'https://kovan.etherscan.io';
break;
default:
throw new Error('unsupported network');
}
utils.defineProperty(this, 'baseUrl', baseUrl);
utils.defineProperty(this, 'apiKey', apiKey || null);

@@ -78,6 +109,7 @@ }

utils.defineProperty(EtherscanProvider.prototype, 'perform', function(method, params) {
if (!params) { params = {}; }
var url = this.testnet ? 'https://ropsten.etherscan.io': 'https://api.etherscan.io';
var url = this.baseUrl;

@@ -115,4 +147,4 @@ var apiKey = '';

url += '/api?module=proxy&action=eth_getStorageAt&address=' + params.address;
url += '&position=' + params.position;
url += '&tag=' + params.blockTag + apiKey;
url += '&position=' + stripHexZeros(params.position);
url += '&tag=' + stripHexZeros(params.blockTag) + apiKey;
return Provider.fetchJSON(url, null, getJsonResult);

@@ -128,3 +160,3 @@

if (params.blockTag) {
url += '/api?module=proxy&action=eth_getBlockByNumber&tag=' + params.blockTag;
url += '/api?module=proxy&action=eth_getBlockByNumber&tag=' + stripHexZeros(params.blockTag);
url += '&boolean=false';

@@ -131,0 +163,0 @@ url += apiKey;

10

index.js

@@ -10,6 +10,6 @@ 'use strict';

function getDefaultProvider(testnet) {
function getDefaultProvider(network) {
return new FallbackProvider([
new InfuraProvider(testnet),
new EtherscanProvider(testnet),
new InfuraProvider(network),
new EtherscanProvider(network),
]);

@@ -24,4 +24,6 @@ }

isProvder: Provider.isProvider,
isProvider: Provider.isProvider,
networks: Provider.networks,
getDefaultProvider:getDefaultProvider,

@@ -28,0 +30,0 @@

@@ -1,3 +0,6 @@

var JsonRpcProvider = require('./json-rpc-provider.js');
'use strict';
var Provider = require('./provider');
var JsonRpcProvider = require('./json-rpc-provider');
var utils = (function() {

@@ -9,9 +12,36 @@ return {

function InfuraProvider(testnet, apiAccessToken) {
function InfuraProvider(network, apiAccessToken) {
if (!(this instanceof InfuraProvider)) { throw new Error('missing new'); }
var host = (testnet ? "ropsten": "mainnet") + '.infura.io';
// Legacy constructor (testnet, chainId, apiAccessToken)
// @TODO: Remove this in the next major release
if (arguments.length === 3) {
apiAccessToken = arguments[2];
network = Provider._legacyConstructor(network, 2, arguments[0], arguments[1]);
} else {
apiAccessToken = null;
network = Provider._legacyConstructor(network, arguments.length, arguments[0], arguments[1]);
}
var host = null;
switch(network.name) {
case 'homestead':
host = 'mainnet.infura.io';
break;
case 'ropsten':
host = 'ropsten.infura.io';
break;
case 'rinkeby':
host = 'rinkeby.infura.io';
break;
case 'kovan':
host = 'kovan.infura.io';
break;
default:
throw new Error('unsupported network');
}
var url = 'https://' + host + '/' + (apiAccessToken || '');
JsonRpcProvider.call(this, url, testnet);
JsonRpcProvider.call(this, url, network);

@@ -18,0 +48,0 @@ utils.defineProperty(this, 'apiAccessToken', apiAccessToken || null);

@@ -51,7 +51,9 @@ 'use strict';

function JsonRpcProvider(url, testnet, chainId) {
function JsonRpcProvider(url, network) {
if (!(this instanceof JsonRpcProvider)) { throw new Error('missing new'); }
Provider.call(this, testnet, chainId);
network = Provider._legacyConstructor(network, arguments.length - 1, arguments[1], arguments[2]);
Provider.call(this, network);
if (!url) { url = 'http://localhost:8545'; }

@@ -58,0 +60,0 @@

{
"name": "ethers-providers",
"version": "2.1.4",
"version": "2.1.5",
"description": "Service provider for Ethereum wallet library.",

@@ -5,0 +5,0 @@ "bugs": {

@@ -7,2 +7,4 @@ 'use strict';

var networks = require('./networks.json');
var utils = (function() {

@@ -131,4 +133,4 @@ var convert = require('ethers-utils/convert');

timestamp: checkNumber,
nonce: utils.hexlify,
difficulty: checkNumber,
nonce: allowNull(utils.hexlify),
difficulty: allowNull(checkNumber),

@@ -175,9 +177,9 @@ gasLimit: utils.bigNumberify,

r: checkUint256,
s: checkUint256,
v: checkNumber,
r: allowNull(checkUint256),
s: allowNull(checkUint256),
v: allowNull(checkNumber),
creates: allowNull(utils.getAddress, null),
raw: utils.hexlify,
raw: allowNull(utils.hexlify),
};

@@ -203,15 +205,19 @@

if (!transaction.raw) {
var raw = [
utils.hexlify(transaction.nonce),
utils.hexlify(transaction.gasPrice),
utils.hexlify(transaction.gasLimit),
(transaction.to || "0x"),
utils.hexlify(transaction.value || '0x'),
utils.hexlify(transaction.data || '0x'),
utils.hexlify(transaction.v || '0x'),
utils.hexlify(transaction.r),
utils.hexlify(transaction.s),
];
transaction.raw = utils.RLP.encode(raw);
// Very loose providers (e.g. TestRPC) don't provide a signature or raw
if (transaction.v && transaction.r && transaction.s) {
var raw = [
utils.hexlify(transaction.nonce),
utils.hexlify(transaction.gasPrice),
utils.hexlify(transaction.gasLimit),
(transaction.to || "0x"),
utils.hexlify(transaction.value || '0x'),
utils.hexlify(transaction.data || '0x'),
utils.hexlify(transaction.v || '0x'),
utils.hexlify(transaction.r),
utils.hexlify(transaction.s),
];
transaction.raw = utils.RLP.encode(raw);
}
}

@@ -228,3 +234,3 @@

if (typeof(networkId) !== 'number') {
if (typeof(networkId) !== 'number' && result.v != null) {
networkId = (result.v - 35) / 2;

@@ -235,2 +241,4 @@ if (networkId < 0) { networkId = 0; }

if (typeof(networkId) !== 'number') { networkId = 0; }
result.networkId = networkId;

@@ -335,22 +343,21 @@

var ensAddressTestnet = '0x112234455c3a32fd11230c42e7bccd4a84e02010';
var ensAddressMainnet = '0x314159265dd8dbb310642f98f50c066173c1259b';
function Provider(testnet, chainId) {
function Provider(network) {
if (!(this instanceof Provider)) { throw new Error('missing new'); }
testnet = !!testnet;
network = Provider._legacyConstructor(network, arguments.length, arguments[0], arguments[1]);
if (chainId == null) {
chainId = (testnet ? Provider.chainId.ropsten: Provider.chainId.homestead);
// Check the ensAddress (if any)
var ensAddress = null;
if (network.ensAddress) {
ensAddress = utils.getAddress(network.ensAddress);
}
// Figure out which ENS to talk to
this.ensAddress = (testnet ? ensAddressTestnet: ensAddressMainnet);
// Setup our network properties
utils.defineProperty(this, 'chainId', network.chainId);
utils.defineProperty(this, 'ensAddress', ensAddress);
utils.defineProperty(this, 'name', network.name);
if (typeof(chainId) !== 'number') { throw new Error('invalid chainId'); }
// @TODO: Remove in the next major release
utils.defineProperty(this, 'testnet', (network.name !== 'homestead'));
utils.defineProperty(this, 'testnet', testnet);
utils.defineProperty(this, 'chainId', chainId);
var events = {};

@@ -462,2 +469,31 @@ utils.defineProperty(this, '_events', events);

*/
utils.defineProperty(Provider, '_legacyConstructor', function(network, length, arg0, arg1) {
// Legacy parameters Provider(testnet:boolean, chainId:Number)
if (typeof(arg0) === 'boolean' || length === 2) {
var testnet = !!arg0;
var chainId = arg1;
// true => testnet, false => mainnet
network = networks[testnet ? 'ropsten': 'homestead'];
// Overriding chain ID
if (length === 2 && chainId != null) {
network = {
chainId: chainId,
ensAddress: network.ensAddress,
name: network.name
};
}
} else if (typeof(network) === 'string') {
network = networks[network];
if (!network) { throw new Error('unknown network'); }
}
if (typeof(network.chainId) !== 'number') { throw new Error('invalid chainId'); }
return network;
});
utils.defineProperty(Provider, 'chainId', {

@@ -473,2 +509,4 @@ homestead: 1,

utils.defineProperty(Provider, 'networks', networks);
utils.defineProperty(Provider, 'fetchJSON', function(url, json, processFunc) {

@@ -475,0 +513,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc