New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@jpmonette/bscscan

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jpmonette/bscscan - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

.env.test

2

index.ts

@@ -1,2 +0,2 @@

import { BscScan } from "./src/client";
import { BscScan } from ".";
import "isomorphic-fetch";

@@ -3,0 +3,0 @@

export default {
preset: "ts-jest",
testEnvironment: "node",
testPathIgnorePatterns: ["/node_modules/", "__tests__/util/"],
collectCoverageFrom: ["src/**/*.{ts,tsx}", "!**/*.d.ts", "!src/typings/**", "!src/__tests__/**"],
testPathIgnorePatterns: ["/node_modules/"],
testRegex: "(/__tests__/.*\\.test)\\.(jsx?|tsx?)$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
};
import { Accounts } from "./modules/accounts";
import { Contracts } from "./modules/contracts";
import { Stats } from "./modules/stats";
import { Transactions } from "./modules/transactions";
import { BscScanOptions } from "./typings";

@@ -7,8 +9,11 @@ declare class BscScan {

baseUrl: string;
accounts: Accounts;
contracts: Contracts;
transactions: Transactions;
stats: Stats;
accounts: Accounts;
constructor(opts: BscScanOptions);
newRequest(method: string | undefined, module: string, action: string, opts?: Record<string, any>): Request;
query(module: string, action: string, opts?: Record<string, any>): Promise<any>;
private do;
do<T>(request: Request): Promise<T>;
}
export { BscScan };

@@ -41,3 +41,5 @@ "use strict";

var accounts_1 = require("./modules/accounts");
var contracts_1 = require("./modules/contracts");
var stats_1 = require("./modules/stats");
var transactions_1 = require("./modules/transactions");
var BASE_URL = "https://api.bscscan.com/api?";

@@ -49,29 +51,35 @@ var BscScan = (function () {

this.baseUrl = opts.baseUrl || BASE_URL;
this.accounts = new accounts_1.Accounts(this);
this.contracts = new contracts_1.Contracts(this);
this.stats = new stats_1.Stats(this);
this.accounts = new accounts_1.Accounts(this);
this.transactions = new transactions_1.Transactions(this);
}
BscScan.prototype.newRequest = function (method, module, action, opts) {
if (method === void 0) { method = "GET"; }
if (opts === void 0) { opts = {}; }
var params = new URLSearchParams({ module: module, action: action });
if (this.apikey) {
params.set("apikey", this.apikey);
}
for (var _i = 0, _a = Object.entries(opts); _i < _a.length; _i++) {
var _b = _a[_i], key = _b[0], value = _b[1];
if (Array.isArray(value)) {
params.set(key, value.join(","));
}
else {
params.set(key, value);
}
}
var headers = new Headers();
headers.set("Content-Type", "application/json; charset=UTF-8");
var init = { method: method, headers: headers };
var url = new URL("/api?" + params.toString(), BASE_URL);
var request = new Request(url.toString(), init);
return request;
};
BscScan.prototype.query = function (module, action, opts) {
if (opts === void 0) { opts = {}; }
return __awaiter(this, void 0, void 0, function () {
var params, _i, _a, _b, key, value, headers, init, url, request;
return __generator(this, function (_c) {
params = new URLSearchParams({ module: module, action: action });
if (this.apikey) {
params.set("apikey", this.apikey);
}
for (_i = 0, _a = Object.entries(opts); _i < _a.length; _i++) {
_b = _a[_i], key = _b[0], value = _b[1];
if (Array.isArray(value)) {
params.set(key, value.join(","));
}
else {
params.set(key, value);
}
}
headers = new Headers();
headers.set("Content-Type", "application/json; charset=UTF-8");
init = { method: "GET", headers: headers };
url = new URL("/api?" + params.toString(), BASE_URL);
request = new Request(url.toString(), init);
return [2, this.do(request)];
return __generator(this, function (_a) {
return [2, this.do(this.newRequest("GET", module, action, opts))];
});

@@ -78,0 +86,0 @@ });

@@ -13,4 +13,4 @@ import { BscScan } from "../client";

getMinedBlocks(opts: GetMinedBlocksRequest): Promise<GetMinedBlocksResponse>;
do(action: string, opts: Record<string, any>): Promise<any>;
private do;
}
export { Accounts };

@@ -88,4 +88,19 @@ "use strict";

return __awaiter(this, void 0, void 0, function () {
var response, e_1;
return __generator(this, function (_a) {
return [2, this.do("getminedblocks", opts)];
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4, this.do("getminedblocks", opts)];
case 1:
response = _a.sent();
return [2, response];
case 2:
e_1 = _a.sent();
if (e_1.message.includes("No transactions found")) {
return [2, []];
}
throw e_1;
case 3: return [2];
}
});

@@ -92,0 +107,0 @@ });

@@ -9,4 +9,4 @@ import { BscScan } from "../client";

getValidators(): Promise<GetValidatorsResponse>;
do(action: string, opts?: Record<string, any>): Promise<any>;
private do;
}
export { Stats };
export * from "./accounts";
export * from "./contracts";
export * from "./stats";
export * from "./transactions";
export declare type BscScanOptions = {

@@ -4,0 +6,0 @@ apikey?: string;

@@ -14,3 +14,5 @@ "use strict";

__exportStar(require("./accounts"), exports);
__exportStar(require("./contracts"), exports);
__exportStar(require("./stats"), exports);
__exportStar(require("./transactions"), exports);
//# sourceMappingURL=index.js.map
{
"name": "@jpmonette/bscscan",
"version": "0.2.0",
"version": "0.2.1",
"description": "Explore the Binance Smart Chain using TypeScript and JavaScript",

@@ -9,3 +9,3 @@ "homepage": "https://github.com/jpmonette/bscscan-ts",

"main": "lib/client.js",
"types": "lib/typings/index.d.ts",
"types": "lib/client.d.ts",
"bugs": {

@@ -20,4 +20,4 @@ "url": "https://github.com/jpmonette/bscscan-ts/issues"

"build": "rimraf lib/ && mkdir lib && tsc",
"test": "export NODE_ENV=test && npx jest --silent --passWithNoTests --coverage && coveralls < coverage/lcov.info",
"test-travis": "yarn test"
"test": "export NODE_ENV=test && npx jest --passWithNoTests",
"test-travis": "export NODE_ENV=test && npx jest --silent --passWithNoTests --coverage"
},

@@ -30,2 +30,3 @@ "devDependencies": {

"coveralls": "^3.1.0",
"dotenv": "^10.0.0",
"eslint": "^7.26.0",

@@ -32,0 +33,0 @@ "isomorphic-fetch": "^3.0.0",

@@ -1,3 +0,7 @@

export const accountResponses: Record<string, unknown> = {
balance: { status: "1", message: "OK", result: "1921440981086393507806711" },
export const accountResponses: Record<string, any> = {
balance: {
status: "1",
message: "OK",
result: "1921440981086393507806711",
},
balancemulti: {

@@ -155,11 +159,23 @@ status: "1",

getminedblocks: {
status: "1",
message: "OK",
result: [
{ blockNumber: "12837584", timeStamp: "1637509278", blockReward: "647708965667033920" },
{ blockNumber: "12837563", timeStamp: "1637509215", blockReward: "507184284612347890" },
{ blockNumber: "12837542", timeStamp: "1637509152", blockReward: "565437075463792362" },
{ blockNumber: "12837521", timeStamp: "1637509089", blockReward: "0" },
],
success: {
status: "1",
message: "OK",
result: [
{ blockNumber: "12837584", timeStamp: "1637509278", blockReward: "647708965667033920" },
{ blockNumber: "12837563", timeStamp: "1637509215", blockReward: "507184284612347890" },
{ blockNumber: "12837542", timeStamp: "1637509152", blockReward: "565437075463792362" },
{ blockNumber: "12837521", timeStamp: "1637509089", blockReward: "0" },
],
},
noBlock: {
status: "0",
message: "No transactions found",
result: [],
},
error: {
status: "0",
message: "API Key Not Found",
result: [],
},
},
};

@@ -0,41 +1,17 @@

import "isomorphic-fetch";
import { BscScan } from "../../client";
import "isomorphic-fetch";
import { server, testAddress1, testAddress2, testAddress3 } from "../server";
import { API_KEY } from "../setup";
const address = "0x515b72ed8a97f42c568d6a143232775018f133c8";
const address2 = "0x161ba15a5f335c9f06bb5bbb0a9ce14076fbb645";
const addresses = [address, address2];
const addresses = [testAddress1, testAddress2];
import { setupServer } from "msw/node";
import { rest } from "msw";
import { accountResponses } from "../data/accounts";
const apikey = "sample-key";
const handlers = [
rest.get(`*/api`, (req, res, ctx) => {
const module = req.url.searchParams.get("module") as string;
const action = req.url.searchParams.get("action") as string;
if (module === "account" && accountResponses[action]) {
return res(ctx.json(accountResponses[action]));
}
throw new Error("endpoint not found");
}),
];
const server = setupServer(...handlers);
describe("account", () => {
const client = new BscScan({ apikey });
const client = new BscScan({ apikey: API_KEY });
beforeAll(() => server.listen());
// Reset any request handlers that we may add during the tests,
// so they don't affect other tests.
afterEach(() => server.resetHandlers());
// Clean up after the tests are finished.
afterAll(() => server.close());
it("should getBalance", async () => {
const params = { address };
const params = { address: testAddress1 };
expect(await client.accounts.getBalance(params)).toMatchSnapshot();

@@ -50,3 +26,3 @@ });

it("should getTxList", async () => {
const params = { address };
const params = { address: testAddress1 };
expect(await client.accounts.getTxList(params)).toMatchSnapshot();

@@ -56,3 +32,3 @@ });

it("should getTxListInternal", async () => {
const params = { address };
const params = { address: testAddress1 };
expect(await client.accounts.getTxListInternal(params)).toMatchSnapshot();

@@ -62,3 +38,3 @@ });

it("should getTokenTx", async () => {
const params = { address };
const params = { address: testAddress1 };
expect(await client.accounts.getTokenTx(params)).toMatchSnapshot();

@@ -68,10 +44,25 @@ });

it("should getTokenNFTTx", async () => {
const params = { address };
const params = { address: testAddress1 };
expect(await client.accounts.getTokenNFTTx(params)).toMatchSnapshot();
});
it("should getMinedBlocks", async () => {
const params = { address };
it("should getMinedBlocks - blocks found", async () => {
const params = { address: testAddress1 };
expect(await client.accounts.getMinedBlocks(params)).toMatchSnapshot();
});
it("should getMinedBlocks - no block", async () => {
const params = { address: testAddress2 };
expect(await client.accounts.getMinedBlocks(params)).toMatchSnapshot();
});
it("should getMinedBlocks - error", async () => {
const params = { address: testAddress3 };
try {
await client.accounts.getMinedBlocks(params);
} catch (e) {
expect(e).toMatchSnapshot();
}
});
});

@@ -7,4 +7,12 @@ import { Accounts } from "./modules/accounts";

/**
* The default production API base url
*/
const BASE_URL = "https://api.bscscan.com/api?";
/**
* A BscScan API client
*
* @class BscScan
*/
class BscScan {

@@ -19,2 +27,7 @@ apikey: string | undefined;

/**
* Creates an instance of BscScan.
* @param {BscScanOptions} opts
* @memberof BscScan
*/
constructor(opts: BscScanOptions) {

@@ -32,2 +45,12 @@ const { apikey } = opts;

/**
* Creates a new HTTP request
*
* @param {string} [method="GET"]
* @param {string} module
* @param {string} action
* @param {Record<string, any>} [opts={}]
* @returns {Request}
* @memberof BscScan
*/
newRequest(method = "GET", module: string, action: string, opts: Record<string, any> = {}): Request {

@@ -59,2 +82,11 @@ const params = new URLSearchParams({ module, action });

/**
* Executes a simplified API query
*
* @param {string} module
* @param {string} action
* @param {Record<string, any>} [opts={}]
* @returns {Promise<any>}
* @memberof BscScan
*/
async query(module: string, action: string, opts: Record<string, any> = {}): Promise<any> {

@@ -64,2 +96,10 @@ return this.do(this.newRequest("GET", module, action, opts));

/**
* Executes an HTTP request
*
* @template T
* @param {Request} request
* @returns {Promise<T>}
* @memberof BscScan
*/
async do<T>(request: Request): Promise<T> {

@@ -66,0 +106,0 @@ const response: Response = await fetch(request);

@@ -20,4 +20,17 @@ import { BscScan } from "../client";

class Accounts {
/**
* Represents the BscScan client
*
* @private
* @type {BscScan}
* @memberof Accounts
*/
private client: BscScan;
/**
* Creates an instance of Accounts.
*
* @param {BscScan} client
* @memberof Accounts
*/
constructor(client: BscScan) {

@@ -27,2 +40,10 @@ this.client = client;

/**
* Get BNB Balance for a Single Address
* https://docs.bscscan.com/api-endpoints/accounts#get-bnb-balance-for-a-single-address
*
* @param {GetBalanceRequest} opts
* @returns {Promise<GetBalanceResponse>}
* @memberof Accounts
*/
async getBalance(opts: GetBalanceRequest): Promise<GetBalanceResponse> {

@@ -32,2 +53,10 @@ return this.do("balance", opts);

/**
* Get BNB Balance for Multiple Addresses in a Single Call
* https://docs.bscscan.com/api-endpoints/accounts#get-bnb-balance-for-multiple-addresses-in-a-single-call
*
* @param {GetBalanceMultiRequest} opts
* @returns {Promise<GetBalanceMultiResponse>}
* @memberof Accounts
*/
async getBalanceMulti(opts: GetBalanceMultiRequest): Promise<GetBalanceMultiResponse> {

@@ -37,2 +66,10 @@ return this.do("balancemulti", opts);

/**
* Get a list of 'Normal' Transactions By Address
* https://docs.bscscan.com/api-endpoints/accounts#get-a-list-of-normal-transactions-by-address
*
* @param {GetTxListRequest} opts
* @returns {Promise<GetTxListResponse>}
* @memberof Accounts
*/
async getTxList(opts: GetTxListRequest): Promise<GetTxListResponse> {

@@ -42,2 +79,9 @@ return this.do("txlist", opts);

/**
* Get a list of 'Internal' Transactions by Address
* https://docs.bscscan.com/api-endpoints/accounts#get-a-list-of-internal-transactions-by-address
* @param {GetTxListInternalRequest} opts
* @returns {Promise<GetTxListInternalResponse>}
* @memberof Accounts
*/
async getTxListInternal(opts: GetTxListInternalRequest): Promise<GetTxListInternalResponse> {

@@ -47,2 +91,9 @@ return this.do("txlistinternal", opts);

/**
* Get a list of 'BEP-20 Token Transfer Events' by Address
* https://docs.bscscan.com/api-endpoints/accounts#get-a-list-of-bep-20-token-transfer-events-by-address
* @param {GetTokenTxRequest} opts
* @returns {Promise<GetTokenTxResponse>}
* @memberof Accounts
*/
async getTokenTx(opts: GetTokenTxRequest): Promise<GetTokenTxResponse> {

@@ -52,2 +103,9 @@ return this.do("tokentx", opts);

/**
* Get a list of 'BEP-721 Token Transfer Events' by Address
* https://docs.bscscan.com/api-endpoints/accounts#get-a-list-of-bep-721-token-transfer-events-by-address
* @param {GetTokenNFTTxRequest} opts
* @returns {Promise<GetTokenNFTTxResponse>}
* @memberof Accounts
*/
async getTokenNFTTx(opts: GetTokenNFTTxRequest): Promise<GetTokenNFTTxResponse> {

@@ -57,2 +115,9 @@ return this.do("tokennfttx", opts);

/**
* Get list of Blocks Validated by Address
* https://docs.bscscan.com/api-endpoints/accounts#get-list-of-blocks-validated-by-address
* @param {GetMinedBlocksRequest} opts
* @returns {Promise<GetMinedBlocksResponse>}
* @memberof Accounts
*/
async getMinedBlocks(opts: GetMinedBlocksRequest): Promise<GetMinedBlocksResponse> {

@@ -70,3 +135,3 @@ try {

async do(action: string, opts: Record<string, any>): Promise<any> {
private async do(action: string, opts: Record<string, any>): Promise<any> {
return this.client.query("account", action, opts);

@@ -73,0 +138,0 @@ }

@@ -27,2 +27,3 @@ import { BscScan } from "../client";

* Creates an instance of Contracts.
*
* @param {BscScan} client

@@ -38,2 +39,3 @@ * @memberof Contracts

* https://docs.bscscan.com/api-endpoints/contracts#get-contract-abi-for-verified-contract-source-codes
*
* @param {GetAbiRequest} opts

@@ -50,2 +52,3 @@ * @returns {Promise<GetAbiResponse>}

* https://docs.bscscan.com/api-endpoints/contracts#get-contract-source-code-for-verified-contract-source-codes
*
* @param {GetSourceCodeRequest} opts

@@ -62,2 +65,3 @@ * @returns {Promise<GetSourceCodeResponse>}

* https://docs.bscscan.com/api-endpoints/contracts#verify-source-code
*
* @param {VerifySourceCodeRequest} opts

@@ -78,2 +82,3 @@ * @returns {Promise<VerifySourceCodeResponse>}

* https://docs.bscscan.com/api-endpoints/contracts#verifying-proxy-contract-using-curl
*
* @param {VerifyProxyContractRequest} opts

@@ -92,2 +97,3 @@ * @returns {Promise<VerifyProxyContractResponse>}

* https://docs.bscscan.com/api-endpoints/contracts#checking-proxy-contract-verification-submission-status-using-curl
*
* @param {CheckProxyVerificationRequest} opts

@@ -94,0 +100,0 @@ * @returns {Promise<CheckProxyVerificationResponse>}

@@ -5,4 +5,16 @@ import { BscScan } from "../client";

class Stats {
/**
* Represents the BscScan client
*
* @private
* @type {BscScan}
* @memberof Stats
*/
private client: BscScan;
/**
* Creates an instance of Stats.
* @param {BscScan} client
* @memberof Stats
*/
constructor(client: BscScan) {

@@ -12,2 +24,8 @@ this.client = client;

/**
* Get BNB Last Price
* https://docs.bscscan.com/api-endpoints/stats-1#get-bnb-last-price
* @returns {Promise<GetBNBLastPriceResponse>}
* @memberof Stats
*/
async getBNBLastPrice(): Promise<GetBNBLastPriceResponse> {

@@ -17,2 +35,8 @@ return this.do("bnbprice");

/**
* Get Total Supply of BNB on the Binance Smart Chain
* https://docs.bscscan.com/api-endpoints/stats-1#get-total-supply-of-bnb-on-the-binance-smart-chain
* @returns {Promise<GetBNBLastPriceResponse>}
* @memberof Stats
*/
async getBNBTotalSupply(): Promise<GetBNBTotalSupplyResponse> {

@@ -22,2 +46,8 @@ return this.do("bnbsupply");

/**
* Get Validators List on the Binance Smart Chain
* https://docs.bscscan.com/api-endpoints/stats-1#get-validators-list-on-the-binance-smart-chain
* @returns {Promise<GetBNBTotalSupplyResponse>}
* @memberof Stats
*/
async getValidators(): Promise<GetValidatorsResponse> {

@@ -27,3 +57,3 @@ return this.do("validators");

async do(action: string, opts?: Record<string, any>): Promise<any> {
private async do(action: string, opts?: Record<string, any>): Promise<any> {
return this.client.query("stats", action, opts);

@@ -30,0 +60,0 @@ }

@@ -5,4 +5,17 @@ import { BscScan } from "../client";

class Transactions {
/**
* Represents the BscScan client
*
* @private
* @type {BscScan}
* @memberof Transactions
*/
private client: BscScan;
/**
* Creates an instance of Transactions.
*
* @param {BscScan} client
* @memberof Transactions
*/
constructor(client: BscScan) {

@@ -12,2 +25,10 @@ this.client = client;

/**
* Check Transaction Receipt Status
* https://docs.bscscan.com/api-endpoints/stats#check-transaction-receipt-status
*
* @param {GetTxReceiptStatusRequest} opts
* @returns {Promise<GetTxReceiptStatusResponse>}
* @memberof Transactions
*/
async getTxReceiptStatus(opts: GetTxReceiptStatusRequest): Promise<GetTxReceiptStatusResponse> {

@@ -17,3 +38,3 @@ return this.do("gettxreceiptstatus", opts);

async do(action: string, opts: Record<string, any>): Promise<any> {
private async do(action: string, opts: Record<string, any>): Promise<any> {
return this.client.query("transaction", action, opts);

@@ -20,0 +41,0 @@ }

@@ -68,3 +68,3 @@ export type GetAbiRequest = {

export type VerifySourceCodeResponse = any;
export type VerifySourceCodeResponse = string;

@@ -71,0 +71,0 @@ export type VerifyProxyContractRequest = {

@@ -25,4 +25,4 @@ {

},
"include": ["src/**/*", "index.ts"],
"exclude": ["node_modules", "dist", "**/*.spec.ts"]
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.spec.ts", "index.ts"]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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