├── .prettierrc.yaml ├── CONTRIBUTORS.md ├── src ├── __tests__ │ ├── setup.ts │ ├── data │ │ ├── transactions.ts │ │ ├── stats.ts │ │ ├── contracts.ts │ │ └── accounts.ts │ ├── modules │ │ ├── __snapshots__ │ │ │ ├── transactions.test.ts.snap │ │ │ ├── stats.test.ts.snap │ │ │ ├── contracts.test.ts.snap │ │ │ └── accounts.test.ts.snap │ │ ├── transactions.test.ts │ │ ├── stats.test.ts │ │ ├── contracts.test.ts │ │ └── accounts.test.ts │ └── server.ts ├── typings │ ├── transactions.ts │ ├── stats.ts │ ├── index.ts │ ├── accounts.ts │ └── contracts.ts ├── modules │ ├── transactions.ts │ ├── stats.ts │ ├── contracts.ts │ └── accounts.ts └── client.ts ├── AUTHORS ├── docs ├── assets │ ├── icons.png │ ├── widgets.png │ ├── icons@2x.png │ ├── widgets@2x.png │ └── highlight.css ├── .nojekyll ├── modules │ ├── client.html │ ├── modules_stats.html │ ├── modules_accounts.html │ ├── modules_contracts.html │ ├── modules_transactions.html │ ├── typings_transactions.html │ └── typings_stats.html ├── modules.html ├── index.html └── classes │ ├── modules_transactions.Transactions.html │ ├── modules_stats.Stats.html │ ├── client.BscScan.html │ ├── modules_contracts.Contracts.html │ └── modules_accounts.Accounts.html ├── .gitignore ├── .eslintrc.json ├── .travis.yml ├── jest.config.ts ├── tsconfig.json ├── LICENSE ├── CONTRIBUTING.md ├── package.json ├── README.md └── CODE_OF_CONDUCT_md /.prettierrc.yaml: -------------------------------------------------------------------------------- 1 | printWidth: 120 2 | -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | Jean-Philippe Monette 2 | -------------------------------------------------------------------------------- /src/__tests__/setup.ts: -------------------------------------------------------------------------------- 1 | export const API_KEY = process.env.API_KEY; 2 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Jean-Philippe Monette (http://blogue.jpmonette.net/) 2 | -------------------------------------------------------------------------------- /docs/assets/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpmonette/bscscan-ts/HEAD/docs/assets/icons.png -------------------------------------------------------------------------------- /docs/assets/widgets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpmonette/bscscan-ts/HEAD/docs/assets/widgets.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .env.* 3 | .vscode 4 | coverage 5 | lib 6 | node_modules 7 | yarn-error.log 8 | -------------------------------------------------------------------------------- /docs/assets/icons@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpmonette/bscscan-ts/HEAD/docs/assets/icons@2x.png -------------------------------------------------------------------------------- /docs/assets/widgets@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpmonette/bscscan-ts/HEAD/docs/assets/widgets@2x.png -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- 1 | TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. -------------------------------------------------------------------------------- /src/__tests__/data/transactions.ts: -------------------------------------------------------------------------------- 1 | export const transactionsResponses: Record = { 2 | gettxreceiptstatus: { status: "1", message: "OK", result: { status: "1" } }, 3 | }; 4 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "plugins": ["@typescript-eslint"], 5 | "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"] 6 | } 7 | -------------------------------------------------------------------------------- /src/__tests__/modules/__snapshots__/transactions.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`transactions should getTxReceiptStatus 1`] = ` 4 | Object { 5 | "status": "1", 6 | } 7 | `; 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "node" 4 | cache: 5 | directories: 6 | - node_modules 7 | before_install: 8 | - export TZ=Europe/London 9 | script: 10 | - yarn test-travis 11 | after_script: 12 | - coveralls < coverage/lcov.info 13 | -------------------------------------------------------------------------------- /src/typings/transactions.ts: -------------------------------------------------------------------------------- 1 | export type GetTxReceiptStatusRequest = { 2 | // the string representing the transaction hash to check the execution status 3 | txhash: string; 4 | }; 5 | 6 | export type GetTxReceiptStatusResponse = { 7 | // 0 for failed transactions and 1 for successful transactions. 8 | status: "0" | "1"; 9 | }; 10 | -------------------------------------------------------------------------------- /jest.config.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | preset: "ts-jest", 3 | testEnvironment: "node", 4 | collectCoverageFrom: ["src/**/*.{ts,tsx}", "!**/*.d.ts", "!src/typings/**", "!src/__tests__/**"], 5 | testPathIgnorePatterns: ["/node_modules/"], 6 | testRegex: "(/__tests__/.*\\.test)\\.(tsx?)$", 7 | moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], 8 | }; 9 | -------------------------------------------------------------------------------- /src/typings/stats.ts: -------------------------------------------------------------------------------- 1 | export type GetBNBTotalSupplyResponse = string; 2 | 3 | export type GetValidatorsResponse = Array; 4 | 5 | export type GetValidatorsResponseItem = { 6 | validatorAddress: string; 7 | validatorName: string; 8 | validatorStatus: string; 9 | validatorVotingPower: string; 10 | validatorVotingPowerProportion: string; 11 | }; 12 | 13 | export type GetBNBLastPriceResponse = { 14 | ethbtc: string; 15 | ethbtc_timestamp: string; 16 | ethusd: string; 17 | ethusd_timestamp: string; 18 | }; 19 | -------------------------------------------------------------------------------- /src/__tests__/modules/transactions.test.ts: -------------------------------------------------------------------------------- 1 | import "isomorphic-fetch"; 2 | import { BscScan } from "../../client"; 3 | import { server } from "../server"; 4 | import { API_KEY } from "../setup"; 5 | 6 | describe("transactions", () => { 7 | const client = new BscScan({ apikey: API_KEY }); 8 | 9 | beforeAll(() => server.listen()); 10 | afterEach(() => server.resetHandlers()); 11 | afterAll(() => server.close()); 12 | 13 | it("should getTxReceiptStatus", async () => { 14 | const opts = { txhash: "0xe9975702518c79caf81d5da65dea689dcac701fcdd063f848d4f03c85392fd00" }; 15 | expect(await client.transactions.getTxReceiptStatus(opts)).toMatchSnapshot(); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/__tests__/modules/stats.test.ts: -------------------------------------------------------------------------------- 1 | import "isomorphic-fetch"; 2 | import { BscScan } from "../../client"; 3 | import { server } from "../server"; 4 | import { API_KEY } from "../setup"; 5 | 6 | describe("stats", () => { 7 | const client = new BscScan({ apikey: API_KEY }); 8 | 9 | beforeAll(() => server.listen()); 10 | afterEach(() => server.resetHandlers()); 11 | afterAll(() => server.close()); 12 | 13 | it("should getBNBLastPrice", async () => { 14 | expect(await client.stats.getBNBLastPrice()).toMatchSnapshot(); 15 | }); 16 | 17 | it("should getBNBTotalSupply", async () => { 18 | expect(await client.stats.getBNBTotalSupply()).toMatchSnapshot(); 19 | }); 20 | 21 | it("should getValidators", async () => { 22 | expect(await client.stats.getValidators()).toMatchSnapshot(); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "lib", 4 | "sourceMap": true, 5 | "noImplicitAny": true, 6 | "removeComments": true, 7 | "module": "commonjs", 8 | "target": "es5", 9 | "lib": ["es7", "dom"], 10 | "moduleResolution": "node", 11 | "rootDir": "src", 12 | "forceConsistentCasingInFileNames": true, 13 | "noImplicitReturns": false, 14 | "noImplicitThis": true, 15 | "noStrictGenericChecks": false, 16 | "esModuleInterop": true, 17 | "resolveJsonModule": true, 18 | "strictNullChecks": true, 19 | "strict": true, 20 | "suppressImplicitAnyIndexErrors": false, 21 | "noUnusedLocals": false, 22 | "declaration": true, 23 | "typeRoots": ["typings", "node_modules/@types"] 24 | }, 25 | "include": ["src/**/*", "index.ts"], 26 | "exclude": ["node_modules", "dist", "**/*.spec.ts"] 27 | } 28 | -------------------------------------------------------------------------------- /src/__tests__/modules/__snapshots__/stats.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`stats should getBNBLastPrice 1`] = ` 4 | Object { 5 | "ethbtc": "0.009928", 6 | "ethbtc_timestamp": "1639590487", 7 | "ethusd": "582.6", 8 | "ethusd_timestamp": "1639590487", 9 | } 10 | `; 11 | 12 | exports[`stats should getBNBTotalSupply 1`] = `"22479013170398300000000000"`; 13 | 14 | exports[`stats should getValidators 1`] = ` 15 | Array [ 16 | Object { 17 | "validatorAddress": "0x9f8ccdafcc39f3c7d6ebf637c9151673cbc36b88", 18 | "validatorName": "", 19 | "validatorStatus": "0", 20 | "validatorVotingPower": "43379676392570", 21 | "validatorVotingPowerProportion": "0.0617", 22 | }, 23 | Object { 24 | "validatorAddress": "0x2465176c461afb316ebc773c61faee85a6515daa", 25 | "validatorName": "", 26 | "validatorStatus": "0", 27 | "validatorVotingPower": "38039845465042", 28 | "validatorVotingPowerProportion": "0.0541", 29 | }, 30 | ] 31 | `; 32 | -------------------------------------------------------------------------------- /src/typings/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./accounts"; 2 | export * from "./contracts"; 3 | export * from "./stats"; 4 | export * from "./transactions"; 5 | 6 | /** 7 | * Options used to initialize a BscScan client 8 | */ 9 | export type BscScanOptions = { 10 | apikey?: string; 11 | baseUrl?: string; 12 | }; 13 | 14 | export type APIResponse = { 15 | status: "1" | "0"; 16 | message: string; 17 | result: T; 18 | }; 19 | 20 | export type Token = { 21 | blockHash: string; 22 | blockNumber: string; 23 | confirmations: string; 24 | contractAddress: string; 25 | cumulativeGasUsed: string; 26 | from: string; 27 | gas: string; 28 | gasPrice: string; 29 | gasUsed: string; 30 | hash: string; 31 | input: string; 32 | nonce: string; 33 | timeStamp: string; 34 | to: string; 35 | tokenDecimal: string; 36 | tokenName: string; 37 | tokenSymbol: string; 38 | transactionIndex: string; 39 | }; 40 | 41 | export type BEP20 = Token & { value: string }; 42 | export type ERC721 = Token & { tokenID: string }; 43 | -------------------------------------------------------------------------------- /src/__tests__/data/stats.ts: -------------------------------------------------------------------------------- 1 | export const statsResponses: Record = { 2 | bnbprice: { 3 | status: "1", 4 | message: "OK", 5 | result: { ethbtc: "0.009928", ethbtc_timestamp: "1639590487", ethusd: "582.6", ethusd_timestamp: "1639590487" }, 6 | }, 7 | bnbsupply: { 8 | status: "1", 9 | message: "OK", 10 | result: "22479013170398300000000000", 11 | }, 12 | validators: { 13 | status: "1", 14 | message: "OK", 15 | result: [ 16 | { 17 | validatorAddress: "0x9f8ccdafcc39f3c7d6ebf637c9151673cbc36b88", 18 | validatorName: "", 19 | validatorStatus: "0", 20 | validatorVotingPower: "43379676392570", 21 | validatorVotingPowerProportion: "0.0617", 22 | }, 23 | { 24 | validatorAddress: "0x2465176c461afb316ebc773c61faee85a6515daa", 25 | validatorName: "", 26 | validatorStatus: "0", 27 | validatorVotingPower: "38039845465042", 28 | validatorVotingPowerProportion: "0.0541", 29 | }, 30 | ], 31 | }, 32 | }; 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2013, Jean-Philippe Monette 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /src/__tests__/modules/__snapshots__/contracts.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`contracts should checkProxyVerification 1`] = `"0xcbdcd3815b5f975e1a2c944a9b2cd1c985a1cb7f"`; 4 | 5 | exports[`contracts should getAbi 1`] = `"[]"`; 6 | 7 | exports[`contracts should getSourceCode 1`] = ` 8 | Array [ 9 | Object { 10 | "ABI": "[]", 11 | "CompilerVersion": "v0.6.12+commit.27d51765", 12 | "ConstructorArguments": "", 13 | "ContractName": "CakeToken", 14 | "EVMVersion": "Default", 15 | "Implementation": "", 16 | "Library": "", 17 | "LicenseType": "None", 18 | "OptimizationUsed": "1", 19 | "Proxy": "0", 20 | "Runs": "5000", 21 | "SourceCode": "pragma solidity 0.6.12;", 22 | "SwarmSource": "ipfs://9755240809e31aec9fa5790314682233ca431b7c4f252d7e4bba347e2e742086", 23 | }, 24 | ] 25 | `; 26 | 27 | exports[`contracts should verifyProxyContract 1`] = `"a7xygt433w43um5fda3m6d9jk62jwtjhqdr9zcwj9fmfzcj14r"`; 28 | 29 | exports[`contracts should verifySourceCode 1`] = `"a7xygt433w43um5fda3m6d9jk62jwtjhqdr9zcwj9fmfzcj14r"`; 30 | -------------------------------------------------------------------------------- /src/modules/transactions.ts: -------------------------------------------------------------------------------- 1 | import { BscScan } from "../client"; 2 | import { GetTxReceiptStatusRequest, GetTxReceiptStatusResponse } from "../typings"; 3 | 4 | class Transactions { 5 | /** 6 | * Represents the BscScan client 7 | * 8 | * @private 9 | * @type {BscScan} 10 | * @memberof Transactions 11 | */ 12 | private client: BscScan; 13 | 14 | /** 15 | * Creates an instance of Transactions. 16 | * 17 | * @param {BscScan} client 18 | * @memberof Transactions 19 | */ 20 | constructor(client: BscScan) { 21 | this.client = client; 22 | } 23 | 24 | /** 25 | * Check Transaction Receipt Status 26 | * https://docs.bscscan.com/api-endpoints/stats#check-transaction-receipt-status 27 | * 28 | * @param {GetTxReceiptStatusRequest} opts 29 | * @returns {Promise} 30 | * @memberof Transactions 31 | */ 32 | async getTxReceiptStatus(opts: GetTxReceiptStatusRequest): Promise { 33 | return this.do("gettxreceiptstatus", opts); 34 | } 35 | 36 | private async do(action: string, opts: Record): Promise { 37 | return this.client.query("transaction", action, opts); 38 | } 39 | } 40 | 41 | export { Transactions }; 42 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are a just a few small guidelines you need to follow. 4 | 5 | ## Submitting a patch 6 | 7 | 1. It's generally best to start by opening a new issue describing the bug or 8 | feature you're intending to fix. Even if you think it's relatively minor, 9 | it's helpful to know what people are working on. Mention in the initial 10 | issue that you are planning to work on that bug or feature so that it can 11 | be assigned to you. 12 | 13 | 2. Create and run tests. Your new addition must be covered by unit tests. 14 | 15 | 3. Follow the normal process of [forking][] the project, and setup a new 16 | branch to work in. 17 | 18 | 4. Do your best to have [well-formed commit messages][] for each change. 19 | This provides consistency throughout the project, and ensures that commit 20 | messages are able to be formatted properly by various git tools. 21 | 22 | 5. Finally, push the commits to your fork and submit a [pull request][]. 23 | 24 | [forking]: https://help.github.com/articles/fork-a-repo 25 | [well-formed commit messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html 26 | [squash]: http://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits 27 | [pull request]: https://help.github.com/articles/creating-a-pull-request 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@jpmonette/bscscan", 3 | "version": "0.2.4", 4 | "description": "Explore the Binance Smart Chain using TypeScript and JavaScript", 5 | "homepage": "https://github.com/jpmonette/bscscan-ts", 6 | "author": "Jean-Philippe Monette ", 7 | "license": "MIT", 8 | "main": "lib/client.js", 9 | "types": "lib/client.d.ts", 10 | "bugs": { 11 | "url": "https://github.com/jpmonette/bscscan-ts/issues" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/jpmonette/bscscan-ts.git" 16 | }, 17 | "scripts": { 18 | "build": "rimraf lib/ && mkdir lib && tsc", 19 | "prepublish": "yarn build", 20 | "test": "export NODE_ENV=test && npx jest --passWithNoTests", 21 | "test-travis": "export NODE_ENV=test && npx jest --silent --passWithNoTests --coverage" 22 | }, 23 | "devDependencies": { 24 | "@types/jest": "^26.0.23", 25 | "@typescript-eslint/eslint-plugin": "^4.23.0", 26 | "@typescript-eslint/parser": "^4.23.0", 27 | "codeclimate-test-reporter": "^0.5.1", 28 | "coveralls": "^3.1.0", 29 | "dotenv": "^10.0.0", 30 | "eslint": "^7.26.0", 31 | "isomorphic-fetch": "^3.0.0", 32 | "jest": "^26.6.3", 33 | "msw": "^0.35.0", 34 | "prettier": "^2.3.0", 35 | "ts-jest": "^26.5.6", 36 | "ts-node": "^9.1.1", 37 | "typedoc": "^0.22.10", 38 | "typescript": "^4.2.4" 39 | } 40 | } -------------------------------------------------------------------------------- /src/__tests__/data/contracts.ts: -------------------------------------------------------------------------------- 1 | export const contractResponses: Record> = { 2 | get: { 3 | getabi: { 4 | status: "1", 5 | message: "OK", 6 | result: "[]", 7 | }, 8 | getsourcecode: { 9 | status: "1", 10 | message: "OK", 11 | result: [ 12 | { 13 | SourceCode: "pragma solidity 0.6.12;", 14 | ABI: "[]", 15 | ContractName: "CakeToken", 16 | CompilerVersion: "v0.6.12+commit.27d51765", 17 | OptimizationUsed: "1", 18 | Runs: "5000", 19 | ConstructorArguments: "", 20 | EVMVersion: "Default", 21 | Library: "", 22 | LicenseType: "None", 23 | Proxy: "0", 24 | Implementation: "", 25 | SwarmSource: "ipfs://9755240809e31aec9fa5790314682233ca431b7c4f252d7e4bba347e2e742086", 26 | }, 27 | ], 28 | }, 29 | }, 30 | post: { 31 | verifysourcecode: { 32 | status: "1", 33 | message: "OK", 34 | result: "a7xygt433w43um5fda3m6d9jk62jwtjhqdr9zcwj9fmfzcj14r", 35 | }, 36 | verifyproxycontract: { 37 | status: "1", 38 | message: "OK", 39 | result: "a7xygt433w43um5fda3m6d9jk62jwtjhqdr9zcwj9fmfzcj14r", 40 | }, 41 | checkproxyverification: { 42 | status: "1", 43 | message: "OK", 44 | result: "0xcbdcd3815b5f975e1a2c944a9b2cd1c985a1cb7f", 45 | }, 46 | }, 47 | }; 48 | -------------------------------------------------------------------------------- /src/__tests__/modules/contracts.test.ts: -------------------------------------------------------------------------------- 1 | import "isomorphic-fetch"; 2 | import { BscScan } from "../../client"; 3 | import { VerifySourceCodeRequest } from "../../typings"; 4 | import { server } from "../server"; 5 | import { API_KEY } from "../setup"; 6 | 7 | describe("contracts", () => { 8 | const client = new BscScan({ apikey: API_KEY }); 9 | 10 | beforeAll(() => server.listen()); 11 | afterEach(() => server.resetHandlers()); 12 | afterAll(() => server.close()); 13 | 14 | it("should getAbi", async () => { 15 | const opts = { address: "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82" }; 16 | expect(await client.contracts.getAbi(opts)).toMatchSnapshot(); 17 | }); 18 | 19 | it("should getSourceCode", async () => { 20 | const opts = { address: "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82" }; 21 | expect(await client.contracts.getSourceCode(opts)).toMatchSnapshot(); 22 | }); 23 | 24 | it("should verifySourceCode", async () => { 25 | const opts: VerifySourceCodeRequest = { 26 | contractAddress: "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82", 27 | contractName: "CAKE", 28 | sourceCode: "", 29 | compilerVersion: "v0.6.12+commit.27d51765", 30 | optimizationUsed: "1", 31 | runs: 5000, 32 | licenseType: "None", 33 | }; 34 | expect(await client.contracts.verifySourceCode(opts)).toMatchSnapshot(); 35 | }); 36 | 37 | it("should verifyProxyContract", async () => { 38 | const opts = { 39 | address: "0xbc46363a7669f6e12353fa95bb067aead3675c29", 40 | expectedImplementation: "0xe45a5176bc0f2c1198e2451c4e4501d4ed9b65a6", 41 | }; 42 | expect(await client.contracts.verifyProxyContract(opts)).toMatchSnapshot(); 43 | }); 44 | 45 | it("should checkProxyVerification", async () => { 46 | const opts = { guid: "gwgrrnfy56zf6vc1fljuejwg6pelnc5yns6fg6y2i6zfpgzquz" }; 47 | expect(await client.contracts.checkProxyVerification(opts)).toMatchSnapshot(); 48 | }); 49 | }); 50 | -------------------------------------------------------------------------------- /src/modules/stats.ts: -------------------------------------------------------------------------------- 1 | import { BscScan } from "../client"; 2 | import { GetBNBLastPriceResponse, GetBNBTotalSupplyResponse, GetValidatorsResponse } from "../typings/stats"; 3 | 4 | class Stats { 5 | /** 6 | * Represents the BscScan client 7 | * 8 | * @private 9 | * @type {BscScan} 10 | * @memberof Stats 11 | */ 12 | private client: BscScan; 13 | 14 | /** 15 | * Creates an instance of Stats. 16 | * @param {BscScan} client 17 | * @memberof Stats 18 | */ 19 | constructor(client: BscScan) { 20 | this.client = client; 21 | } 22 | 23 | /** 24 | * Get BNB Last Price 25 | * https://docs.bscscan.com/api-endpoints/stats-1#get-bnb-last-price 26 | * @returns {Promise} 27 | * @memberof Stats 28 | */ 29 | async getBNBLastPrice(): Promise { 30 | return this.do("bnbprice"); 31 | } 32 | 33 | /** 34 | * Get Total Supply of BNB on the Binance Smart Chain 35 | * https://docs.bscscan.com/api-endpoints/stats-1#get-total-supply-of-bnb-on-the-binance-smart-chain 36 | * @returns {Promise} 37 | * @memberof Stats 38 | */ 39 | async getBNBTotalSupply(): Promise { 40 | return this.do("bnbsupply"); 41 | } 42 | 43 | /** 44 | * Get Validators List on the Binance Smart Chain 45 | * https://docs.bscscan.com/api-endpoints/stats-1#get-validators-list-on-the-binance-smart-chain 46 | * @returns {Promise} 47 | * @memberof Stats 48 | */ 49 | async getValidators(): Promise { 50 | return this.do("validators"); 51 | } 52 | 53 | private async do(action: string, opts?: Record): Promise { 54 | return this.client.query("stats", action, opts); 55 | } 56 | 57 | // todo: dailytxnfee 58 | // todo: dailynewaddress 59 | // todo: dailynetutilization 60 | // todo: dailytx 61 | // todo: bnbdailyprice 62 | } 63 | 64 | export { Stats }; 65 | -------------------------------------------------------------------------------- /src/__tests__/server.ts: -------------------------------------------------------------------------------- 1 | import dotenv from "dotenv"; 2 | dotenv.config(); 3 | import "isomorphic-fetch"; 4 | import { rest } from "msw"; 5 | import { setupServer } from "msw/node"; 6 | import { accountResponses } from "./data/accounts"; 7 | import { contractResponses } from "./data/contracts"; 8 | import { statsResponses } from "./data/stats"; 9 | import { transactionsResponses } from "./data/transactions"; 10 | 11 | export const testAddress1 = "1"; 12 | export const testAddress2 = "2"; 13 | export const testAddress3 = "3"; 14 | 15 | const handlers = [ 16 | rest.get(`*/api`, (req, res, ctx) => { 17 | const module = req.url.searchParams.get("module") as string; 18 | const action = req.url.searchParams.get("action") as string; 19 | const address = req.url.searchParams.get("address") as string; 20 | 21 | if (module === "account" && accountResponses[action]) { 22 | if (action === "getminedblocks") { 23 | if (address === testAddress1) { 24 | return res(ctx.json(accountResponses["getminedblocks"].success)); 25 | } else if (address === testAddress2) { 26 | return res(ctx.json(accountResponses["getminedblocks"].noBlock)); 27 | } else { 28 | return res(ctx.json(accountResponses["getminedblocks"].error)); 29 | } 30 | } 31 | return res(ctx.json(accountResponses[action])); 32 | } 33 | 34 | if (module === "contract" && contractResponses.get[action]) { 35 | return res(ctx.json(contractResponses.get[action])); 36 | } 37 | 38 | if (module === "transaction" && transactionsResponses[action]) { 39 | return res(ctx.json(transactionsResponses[action])); 40 | } 41 | 42 | if (module === "stats" && statsResponses[action]) { 43 | return res(ctx.json(statsResponses[action])); 44 | } 45 | 46 | throw new Error("endpoint not found"); 47 | }), 48 | 49 | rest.post(`*/api`, (req, res, ctx) => { 50 | const module = req.url.searchParams.get("module") as string; 51 | const action = req.url.searchParams.get("action") as string; 52 | 53 | if (module === "contract" && contractResponses.post[action]) { 54 | return res(ctx.json(contractResponses.post[action])); 55 | } 56 | 57 | throw new Error("endpoint not found"); 58 | }), 59 | ]; 60 | 61 | export const server = setupServer(...handlers); 62 | -------------------------------------------------------------------------------- /src/__tests__/modules/accounts.test.ts: -------------------------------------------------------------------------------- 1 | import "isomorphic-fetch"; 2 | import { BscScan } from "../../client"; 3 | import { server, testAddress1, testAddress2, testAddress3 } from "../server"; 4 | import { API_KEY } from "../setup"; 5 | 6 | const addresses = [testAddress1, testAddress2]; 7 | 8 | describe("account", () => { 9 | const client = new BscScan({ apikey: API_KEY }); 10 | 11 | beforeAll(() => server.listen()); 12 | afterEach(() => server.resetHandlers()); 13 | afterAll(() => server.close()); 14 | 15 | it("should getBalance", async () => { 16 | const params = { address: testAddress1 }; 17 | expect(await client.accounts.getBalance(params)).toMatchSnapshot(); 18 | }); 19 | 20 | it("should getBalanceMulti", async () => { 21 | const params = { address: addresses }; 22 | expect(await client.accounts.getBalanceMulti(params)).toMatchSnapshot(); 23 | }); 24 | 25 | it("should getTxList", async () => { 26 | const params = { address: testAddress1 }; 27 | expect(await client.accounts.getTxList(params)).toMatchSnapshot(); 28 | }); 29 | 30 | it("should getTxListInternal", async () => { 31 | const params = { address: testAddress1 }; 32 | expect(await client.accounts.getTxListInternal(params)).toMatchSnapshot(); 33 | }); 34 | 35 | it("should getTokenTx", async () => { 36 | const params = { address: testAddress1 }; 37 | expect(await client.accounts.getTokenTx(params)).toMatchSnapshot(); 38 | }); 39 | 40 | it("should getTokenNFTTx", async () => { 41 | const params = { address: testAddress1 }; 42 | expect(await client.accounts.getTokenNFTTx(params)).toMatchSnapshot(); 43 | }); 44 | 45 | it("should getMinedBlocks - blocks found", async () => { 46 | const params = { address: testAddress1 }; 47 | expect(await client.accounts.getMinedBlocks(params)).toMatchSnapshot(); 48 | }); 49 | 50 | it("should getMinedBlocks - no block", async () => { 51 | const params = { address: testAddress2 }; 52 | expect(await client.accounts.getMinedBlocks(params)).toMatchSnapshot(); 53 | }); 54 | 55 | it("should getMinedBlocks - error", async () => { 56 | const params = { address: testAddress3 }; 57 | 58 | try { 59 | await client.accounts.getMinedBlocks(params); 60 | } catch (e) { 61 | expect(e).toMatchSnapshot(); 62 | } 63 | }); 64 | }); 65 | -------------------------------------------------------------------------------- /docs/assets/highlight.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --light-hl-0: #000000; 3 | --dark-hl-0: #D4D4D4; 4 | --light-hl-1: #AF00DB; 5 | --dark-hl-1: #C586C0; 6 | --light-hl-2: #001080; 7 | --dark-hl-2: #9CDCFE; 8 | --light-hl-3: #A31515; 9 | --dark-hl-3: #CE9178; 10 | --light-hl-4: #0000FF; 11 | --dark-hl-4: #569CD6; 12 | --light-hl-5: #0070C1; 13 | --dark-hl-5: #4FC1FF; 14 | --light-hl-6: #795E26; 15 | --dark-hl-6: #DCDCAA; 16 | --light-hl-7: #008000; 17 | --dark-hl-7: #6A9955; 18 | --light-code-background: #FFFFFF; 19 | --dark-code-background: #1E1E1E; 20 | } 21 | 22 | @media (prefers-color-scheme: light) { :root { 23 | --hl-0: var(--light-hl-0); 24 | --hl-1: var(--light-hl-1); 25 | --hl-2: var(--light-hl-2); 26 | --hl-3: var(--light-hl-3); 27 | --hl-4: var(--light-hl-4); 28 | --hl-5: var(--light-hl-5); 29 | --hl-6: var(--light-hl-6); 30 | --hl-7: var(--light-hl-7); 31 | --code-background: var(--light-code-background); 32 | } } 33 | 34 | @media (prefers-color-scheme: dark) { :root { 35 | --hl-0: var(--dark-hl-0); 36 | --hl-1: var(--dark-hl-1); 37 | --hl-2: var(--dark-hl-2); 38 | --hl-3: var(--dark-hl-3); 39 | --hl-4: var(--dark-hl-4); 40 | --hl-5: var(--dark-hl-5); 41 | --hl-6: var(--dark-hl-6); 42 | --hl-7: var(--dark-hl-7); 43 | --code-background: var(--dark-code-background); 44 | } } 45 | 46 | body.light { 47 | --hl-0: var(--light-hl-0); 48 | --hl-1: var(--light-hl-1); 49 | --hl-2: var(--light-hl-2); 50 | --hl-3: var(--light-hl-3); 51 | --hl-4: var(--light-hl-4); 52 | --hl-5: var(--light-hl-5); 53 | --hl-6: var(--light-hl-6); 54 | --hl-7: var(--light-hl-7); 55 | --code-background: var(--light-code-background); 56 | } 57 | 58 | body.dark { 59 | --hl-0: var(--dark-hl-0); 60 | --hl-1: var(--dark-hl-1); 61 | --hl-2: var(--dark-hl-2); 62 | --hl-3: var(--dark-hl-3); 63 | --hl-4: var(--dark-hl-4); 64 | --hl-5: var(--dark-hl-5); 65 | --hl-6: var(--dark-hl-6); 66 | --hl-7: var(--dark-hl-7); 67 | --code-background: var(--dark-code-background); 68 | } 69 | 70 | .hl-0 { color: var(--hl-0); } 71 | .hl-1 { color: var(--hl-1); } 72 | .hl-2 { color: var(--hl-2); } 73 | .hl-3 { color: var(--hl-3); } 74 | .hl-4 { color: var(--hl-4); } 75 | .hl-5 { color: var(--hl-5); } 76 | .hl-6 { color: var(--hl-6); } 77 | .hl-7 { color: var(--hl-7); } 78 | pre, code { background: var(--code-background); } 79 | -------------------------------------------------------------------------------- /src/typings/accounts.ts: -------------------------------------------------------------------------------- 1 | import { BEP20, ERC721 } from "."; 2 | 3 | type Sort = "asc" | "desc"; 4 | type Tag = "latest" | string; 5 | type BlockType = "blocks" | string; 6 | 7 | export type Pagination = { 8 | sort?: Sort; 9 | startblock?: number; 10 | endblock?: number; 11 | page?: number; 12 | offset?: number; 13 | }; 14 | 15 | export type GetBalanceRequest = { 16 | address: string; 17 | tag?: Tag; 18 | }; 19 | 20 | export type GetBalanceResponse = string; 21 | 22 | export type GetBalanceMultiRequest = { 23 | address: string[]; 24 | tag?: Tag; 25 | }; 26 | 27 | export type GetBalanceMultiResponse = Array; 28 | 29 | export type GetBalanceMultiResponseItem = { 30 | account: string; 31 | balance: string; 32 | }; 33 | 34 | export type GetTxListRequest = Pagination & { 35 | address: string; 36 | }; 37 | 38 | export type GetTxListResponse = Array; 39 | 40 | export type GetTxListResponseItem = { 41 | blockHash: string; 42 | blockNumber: string; 43 | confirmations: string; 44 | contractAddress: string; 45 | cumulativeGasUsed: string; 46 | from: string; 47 | gas: string; 48 | gasPrice: string; 49 | gasUsed: string; 50 | hash: string; 51 | input: string; 52 | isError: string; 53 | nonce: string; 54 | timeStamp: string; 55 | to: string; 56 | transactionIndex: string; 57 | txreceipt_status: string; 58 | value: string; 59 | }; 60 | 61 | export type GetTxListInternalRequest = GetTxListRequest; 62 | 63 | export type GetTxListInternalResponse = Array; 64 | 65 | export type GetTxListInternalResponseItem = { 66 | blockNumber: string; 67 | contractAddress: string; 68 | errCode: string; 69 | from: string; 70 | gas: string; 71 | gasUsed: string; 72 | hash: string; 73 | input: string; 74 | isError: string; 75 | timeStamp: string; 76 | to: string; 77 | traceId: string; 78 | type: string; 79 | value: string; 80 | }; 81 | 82 | export type GetTokenTxRequest = GetTxListRequest & { 83 | contractaddress?: string; 84 | }; 85 | 86 | export type GetTokenTxResponse = Array; 87 | 88 | export type GetTokenNFTTxRequest = Pagination & { 89 | address: string; 90 | }; 91 | 92 | export type GetTokenNFTTxResponse = Array; 93 | 94 | export type GetMinedBlocksRequest = Pagination & { 95 | address: string; 96 | blocktype?: BlockType; 97 | }; 98 | 99 | export type GetMinedBlocksResponse = Array; 100 | 101 | export type GetMinedBlocksResponseItem = { 102 | blockNumber: string; 103 | timeStamp: string; 104 | blockReward: string; 105 | }; 106 | -------------------------------------------------------------------------------- /src/typings/contracts.ts: -------------------------------------------------------------------------------- 1 | export type GetAbiRequest = { 2 | // the contract address that has a verified source code 3 | address: string; 4 | }; 5 | 6 | export type GetAbiResponse = string; 7 | 8 | export type GetSourceCodeRequest = { 9 | // the contract address that has a verified source code 10 | address: string; 11 | }; 12 | 13 | export type GetSourceCodeResponse = Array; 14 | 15 | export type GetSourceCodeResponseItem = { 16 | SourceCode: string; 17 | ABI: string; 18 | ContractName: string; 19 | CompilerVersion: string; 20 | OptimizationUsed: string; 21 | Runs: string; 22 | ConstructorArguments: string; 23 | EVMVersion: string; 24 | Library: string; 25 | LicenseType: string; 26 | Proxy: string; 27 | Implementation: string; 28 | SwarmSource: string; 29 | }; 30 | 31 | export type VerifySourceCodeRequest = { 32 | contractAddress: string; 33 | sourceCode: string; 34 | // solidity-single-file (default) or solidity-standard-json-input (for std-input-json-format support) 35 | codeFormat?: "solidity-single-file" | "solidity-standard-json-input"; 36 | contractName: string; 37 | // see https://bscscan.com/solcversions for list of support versions 38 | compilerVersion: string; 39 | // 0 = No Optimization, 1 = Optimization used (applicable when codeformat=solidity-single-file) 40 | optimizationUsed: "0" | "1"; 41 | // set to 200 as default unless otherwise (applicable when codeformat=solidity-single-file) 42 | runs: number; 43 | constructorArguments?: string; 44 | // leave blank for compiler default, homestead, tangerineWhistle, spuriousDragon, byzantium, constantinople, petersburg, istanbul (applicable when codeformat=solidity-single-file) 45 | evmVersion?: string; 46 | // id codes 1-12 where 1=No License .. 12=Apache 2.0, see https://bscscan.com/contract-license-types 47 | licenseType: string; 48 | libraryName1?: string; 49 | libraryAddress1?: string; 50 | libraryName2?: string; 51 | libraryAddress2?: string; 52 | libraryName3?: string; 53 | libraryAddress3?: string; 54 | libraryName4?: string; 55 | libraryAddress4?: string; 56 | libraryName5?: string; 57 | libraryAddress5?: string; 58 | libraryName6?: string; 59 | libraryAddress6?: string; 60 | libraryName7?: string; 61 | libraryAddress7?: string; 62 | libraryName8?: string; 63 | libraryAddress8?: string; 64 | libraryName9?: string; 65 | libraryAddress9?: string; 66 | libraryName10?: string; 67 | libraryAddress10?: string; 68 | }; 69 | 70 | export type VerifySourceCodeResponse = string; 71 | 72 | export type VerifyProxyContractRequest = { 73 | address: string; 74 | expectedImplementation?: string; 75 | }; 76 | 77 | export type VerifyProxyContractResponse = string; 78 | 79 | export type CheckProxyVerificationRequest = { 80 | guid: string; 81 | }; 82 | 83 | export type CheckProxyVerificationResponse = string; 84 | -------------------------------------------------------------------------------- /src/client.ts: -------------------------------------------------------------------------------- 1 | import { Accounts } from "./modules/accounts"; 2 | import { Contracts } from "./modules/contracts"; 3 | import { Stats } from "./modules/stats"; 4 | import { Transactions } from "./modules/transactions"; 5 | import { APIResponse, BscScanOptions } from "./typings"; 6 | 7 | /** 8 | * The default production API base url 9 | */ 10 | const BASE_URL = "https://api.bscscan.com/api?"; 11 | 12 | /** 13 | * A BscScan API client 14 | * 15 | * @class BscScan 16 | */ 17 | class BscScan { 18 | apikey: string | undefined; 19 | baseUrl: string; 20 | 21 | accounts: Accounts; 22 | contracts: Contracts; 23 | transactions: Transactions; 24 | stats: Stats; 25 | 26 | /** 27 | * Creates an instance of BscScan. 28 | * @param {BscScanOptions} opts 29 | * @memberof BscScan 30 | */ 31 | constructor(opts: BscScanOptions) { 32 | const { apikey } = opts; 33 | 34 | this.apikey = apikey; 35 | this.baseUrl = opts.baseUrl || BASE_URL; 36 | 37 | this.accounts = new Accounts(this); 38 | this.contracts = new Contracts(this); 39 | this.stats = new Stats(this); 40 | this.transactions = new Transactions(this); 41 | } 42 | 43 | /** 44 | * Creates a new HTTP request 45 | * 46 | * @param {string} [method="GET"] 47 | * @param {string} module 48 | * @param {string} action 49 | * @param {Record} [opts={}] 50 | * @returns {Request} 51 | * @memberof BscScan 52 | */ 53 | newRequest(method = "GET", module: string, action: string, opts: Record = {}): Request { 54 | const params = new URLSearchParams({ module, action }); 55 | 56 | if (this.apikey) { 57 | params.set("apikey", this.apikey); 58 | } 59 | 60 | for (const [key, value] of Object.entries(opts)) { 61 | if (Array.isArray(value)) { 62 | params.set(key, value.join(",")); 63 | } else { 64 | params.set(key, value); 65 | } 66 | } 67 | 68 | const headers: Headers = new Headers(); 69 | headers.set("Content-Type", "application/json; charset=UTF-8"); 70 | 71 | const init: RequestInit = { method, headers }; 72 | 73 | const url = new URL("/api?" + params.toString(), this.baseUrl); 74 | 75 | const request = new Request(url.toString(), init); 76 | return request; 77 | } 78 | 79 | /** 80 | * Executes a simplified API query 81 | * 82 | * @param {string} module 83 | * @param {string} action 84 | * @param {Record} [opts={}] 85 | * @returns {Promise} 86 | * @memberof BscScan 87 | */ 88 | async query(module: string, action: string, opts: Record = {}): Promise { 89 | return this.do(this.newRequest("GET", module, action, opts)); 90 | } 91 | 92 | /** 93 | * Executes an HTTP request 94 | * 95 | * @template T 96 | * @param {Request} request 97 | * @returns {Promise} 98 | * @memberof BscScan 99 | */ 100 | async do(request: Request): Promise { 101 | const response: Response = await fetch(request); 102 | const responseBody: APIResponse = await response.json(); 103 | 104 | if (responseBody.status === "0") { 105 | throw new Error(responseBody.message + " - " + responseBody.result); 106 | } 107 | 108 | return responseBody.result; 109 | } 110 | } 111 | 112 | export { BscScan }; 113 | -------------------------------------------------------------------------------- /src/modules/contracts.ts: -------------------------------------------------------------------------------- 1 | import { BscScan } from "../client"; 2 | import { 3 | CheckProxyVerificationRequest, 4 | CheckProxyVerificationResponse, 5 | GetAbiRequest, 6 | GetAbiResponse, 7 | GetSourceCodeRequest, 8 | GetSourceCodeResponse, 9 | VerifyProxyContractRequest, 10 | VerifyProxyContractResponse, 11 | VerifySourceCodeRequest, 12 | VerifySourceCodeResponse, 13 | } from "../typings"; 14 | 15 | class Contracts { 16 | /** 17 | * Represents the BscScan client 18 | * 19 | * @private 20 | * @type {BscScan} 21 | * @memberof Contracts 22 | */ 23 | private client: BscScan; 24 | 25 | /** 26 | * Creates an instance of Contracts. 27 | * 28 | * @param {BscScan} client 29 | * @memberof Contracts 30 | */ 31 | constructor(client: BscScan) { 32 | this.client = client; 33 | } 34 | 35 | /** 36 | * Get Contract ABI for Verified Contract Source Codes 37 | * https://docs.bscscan.com/api-endpoints/contracts#get-contract-abi-for-verified-contract-source-codes 38 | * 39 | * @param {GetAbiRequest} opts 40 | * @returns {Promise} 41 | * @memberof Contracts 42 | */ 43 | async getAbi(opts: GetAbiRequest): Promise { 44 | return this.do("getabi", opts); 45 | } 46 | 47 | /** 48 | * Get Contract Source Code for Verified Contract Source Codes 49 | * https://docs.bscscan.com/api-endpoints/contracts#get-contract-source-code-for-verified-contract-source-codes 50 | * 51 | * @param {GetSourceCodeRequest} opts 52 | * @returns {Promise} 53 | * @memberof Contracts 54 | */ 55 | async getSourceCode(opts: GetSourceCodeRequest): Promise { 56 | return this.do("getsourcecode", opts); 57 | } 58 | 59 | /** 60 | * Verify Source Code 61 | * https://docs.bscscan.com/api-endpoints/contracts#verify-source-code 62 | * 63 | * @param {VerifySourceCodeRequest} opts 64 | * @returns {Promise} 65 | * @memberof Contracts 66 | */ 67 | async verifySourceCode(opts: VerifySourceCodeRequest): Promise { 68 | const request = this.client.newRequest("POST", "contract", "verifysourcecode", opts); 69 | // @ts-ignore 70 | return this.client.do(request); 71 | } 72 | 73 | // todo: checkverifystatus 74 | 75 | /** 76 | * Verifying Proxy Contract 77 | * https://docs.bscscan.com/api-endpoints/contracts#verifying-proxy-contract-using-curl 78 | * 79 | * @param {VerifyProxyContractRequest} opts 80 | * @returns {Promise} 81 | * @memberof Contracts 82 | */ 83 | async verifyProxyContract(opts: VerifyProxyContractRequest): Promise { 84 | const request = this.client.newRequest("POST", "contract", "verifyproxycontract", opts); 85 | // @ts-ignore 86 | return this.client.do(request); 87 | } 88 | 89 | /** 90 | * Checking Proxy Contract Verification Submission Status 91 | * https://docs.bscscan.com/api-endpoints/contracts#checking-proxy-contract-verification-submission-status-using-curl 92 | * 93 | * @param {CheckProxyVerificationRequest} opts 94 | * @returns {Promise} 95 | * @memberof Contracts 96 | */ 97 | async checkProxyVerification(opts: CheckProxyVerificationRequest): Promise { 98 | const request = this.client.newRequest("POST", "contract", "checkproxyverification", opts); 99 | // @ts-ignore 100 | return this.client.do(request); 101 | } 102 | 103 | private async do(action: string, opts: Record): Promise { 104 | return this.client.query("contract", action, opts); 105 | } 106 | } 107 | 108 | export { Contracts }; 109 | -------------------------------------------------------------------------------- /docs/modules/client.html: -------------------------------------------------------------------------------- 1 | client | @jpmonette/bscscan
Options
All
  • Public
  • Public/Protected
  • All
Menu

Legend

  • Type alias
  • Type alias with type parameter
  • Class

Settings

Theme

Generated using TypeDoc

-------------------------------------------------------------------------------- /docs/modules/modules_stats.html: -------------------------------------------------------------------------------- 1 | modules/stats | @jpmonette/bscscan
Options
All
  • Public
  • Public/Protected
  • All
Menu

Legend

  • Type alias
  • Type alias with type parameter
  • Class

Settings

Theme

Generated using TypeDoc

-------------------------------------------------------------------------------- /docs/modules/modules_accounts.html: -------------------------------------------------------------------------------- 1 | modules/accounts | @jpmonette/bscscan
Options
All
  • Public
  • Public/Protected
  • All
Menu

Module modules/accounts

Legend

  • Type alias
  • Type alias with type parameter
  • Class

Settings

Theme

Generated using TypeDoc

-------------------------------------------------------------------------------- /docs/modules/modules_contracts.html: -------------------------------------------------------------------------------- 1 | modules/contracts | @jpmonette/bscscan
Options
All
  • Public
  • Public/Protected
  • All
Menu

Module modules/contracts

Legend

  • Type alias
  • Type alias with type parameter
  • Class

Settings

Theme

Generated using TypeDoc

-------------------------------------------------------------------------------- /docs/modules/modules_transactions.html: -------------------------------------------------------------------------------- 1 | modules/transactions | @jpmonette/bscscan
Options
All
  • Public
  • Public/Protected
  • All
Menu

Module modules/transactions

Legend

  • Type alias
  • Type alias with type parameter
  • Class

Settings

Theme

Generated using TypeDoc

-------------------------------------------------------------------------------- /src/modules/accounts.ts: -------------------------------------------------------------------------------- 1 | import { BscScan } from "../client"; 2 | import { 3 | GetBalanceMultiRequest, 4 | GetBalanceMultiResponse, 5 | GetBalanceRequest, 6 | GetBalanceResponse, 7 | GetTokenNFTTxRequest, 8 | GetTokenNFTTxResponse, 9 | GetTokenTxRequest, 10 | GetTokenTxResponse, 11 | GetTxListInternalRequest, 12 | GetTxListInternalResponse, 13 | GetTxListRequest, 14 | GetTxListResponse, 15 | GetMinedBlocksRequest, 16 | GetMinedBlocksResponse, 17 | } from "../typings/accounts"; 18 | 19 | class Accounts { 20 | /** 21 | * Represents the BscScan client 22 | * 23 | * @private 24 | * @type {BscScan} 25 | * @memberof Accounts 26 | */ 27 | private client: BscScan; 28 | 29 | /** 30 | * Creates an instance of Accounts. 31 | * 32 | * @param {BscScan} client 33 | * @memberof Accounts 34 | */ 35 | constructor(client: BscScan) { 36 | this.client = client; 37 | } 38 | 39 | /** 40 | * Get BNB Balance for a Single Address 41 | * https://docs.bscscan.com/api-endpoints/accounts#get-bnb-balance-for-a-single-address 42 | * 43 | * @param {GetBalanceRequest} opts 44 | * @returns {Promise} 45 | * @memberof Accounts 46 | */ 47 | async getBalance(opts: GetBalanceRequest): Promise { 48 | return this.do("balance", opts); 49 | } 50 | 51 | /** 52 | * Get BNB Balance for Multiple Addresses in a Single Call 53 | * https://docs.bscscan.com/api-endpoints/accounts#get-bnb-balance-for-multiple-addresses-in-a-single-call 54 | * 55 | * @param {GetBalanceMultiRequest} opts 56 | * @returns {Promise} 57 | * @memberof Accounts 58 | */ 59 | async getBalanceMulti(opts: GetBalanceMultiRequest): Promise { 60 | return this.do("balancemulti", opts); 61 | } 62 | 63 | /** 64 | * Get a list of 'Normal' Transactions By Address 65 | * https://docs.bscscan.com/api-endpoints/accounts#get-a-list-of-normal-transactions-by-address 66 | * 67 | * @param {GetTxListRequest} opts 68 | * @returns {Promise} 69 | * @memberof Accounts 70 | */ 71 | async getTxList(opts: GetTxListRequest): Promise { 72 | return this.do("txlist", opts); 73 | } 74 | 75 | /** 76 | * Get a list of 'Internal' Transactions by Address 77 | * https://docs.bscscan.com/api-endpoints/accounts#get-a-list-of-internal-transactions-by-address 78 | * @param {GetTxListInternalRequest} opts 79 | * @returns {Promise} 80 | * @memberof Accounts 81 | */ 82 | async getTxListInternal(opts: GetTxListInternalRequest): Promise { 83 | return this.do("txlistinternal", opts); 84 | } 85 | 86 | /** 87 | * Get a list of 'BEP-20 Token Transfer Events' by Address 88 | * https://docs.bscscan.com/api-endpoints/accounts#get-a-list-of-bep-20-token-transfer-events-by-address 89 | * @param {GetTokenTxRequest} opts 90 | * @returns {Promise} 91 | * @memberof Accounts 92 | */ 93 | async getTokenTx(opts: GetTokenTxRequest): Promise { 94 | return this.do("tokentx", opts); 95 | } 96 | 97 | /** 98 | * Get a list of 'BEP-721 Token Transfer Events' by Address 99 | * https://docs.bscscan.com/api-endpoints/accounts#get-a-list-of-bep-721-token-transfer-events-by-address 100 | * @param {GetTokenNFTTxRequest} opts 101 | * @returns {Promise} 102 | * @memberof Accounts 103 | */ 104 | async getTokenNFTTx(opts: GetTokenNFTTxRequest): Promise { 105 | return this.do("tokennfttx", opts); 106 | } 107 | 108 | /** 109 | * Get list of Blocks Validated by Address 110 | * https://docs.bscscan.com/api-endpoints/accounts#get-list-of-blocks-validated-by-address 111 | * @param {GetMinedBlocksRequest} opts 112 | * @returns {Promise} 113 | * @memberof Accounts 114 | */ 115 | async getMinedBlocks(opts: GetMinedBlocksRequest): Promise { 116 | try { 117 | const response = await this.do("getminedblocks", opts); 118 | return response; 119 | } catch (e) { 120 | if (e.message.includes("No transactions found")) { 121 | return []; 122 | } 123 | throw e; 124 | } 125 | } 126 | 127 | private async do(action: string, opts: Record): Promise { 128 | return this.client.query("account", action, opts); 129 | } 130 | 131 | // todo: balancehistory 132 | } 133 | 134 | export { Accounts }; 135 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

@jpmonette/bscscan

2 | 3 |

@jpmonette/bscscan - Explore the Binance Smart Chain using TypeScript and JavaScript

4 | 5 |

6 | Build Status Coverage Status npm version Tested with Jest License: MIT 7 |

8 | 9 | --- 10 | 11 | **👩🏻‍💻 Developer Ready**: Interact with the BscScan API in no time! 12 | 13 | **💪🏼 Strongly Typed**: Developed using TypeScript. 14 | 15 | **🔒 Battleproof**: Tested using Jest. 16 | 17 | # Getting Started 18 | 19 | ## Installation 20 | 21 | ```bash 22 | $ yarn add @jpmonette/bscscan 23 | ``` 24 | 25 | ## Usage 26 | 27 | ### Import & Initialize 28 | 29 | ```ts 30 | import { BscScan } from "@jpmonette/bscscan"; 31 | 32 | const client = new BscScan({ apikey: "api-key" }); 33 | ``` 34 | 35 | ### Get Account Balance 36 | 37 | ```ts 38 | const balance = await client.accounts.getBalance({ address: "0x4e656459ed25bf986eea1196bc1b00665401645d" }); 39 | 40 | console.log(balance); 41 | // 13305527100000000000 42 | ``` 43 | 44 | ### Get Transaction List 45 | 46 | ```ts 47 | const txlist = await client.accounts.getTxList({ address: "0x4e656459ed25bf986eea1196bc1b00665401645d" }); 48 | 49 | console.log(txlist); 50 | //[ 51 | // { 52 | // "blockNumber": "12476392", 53 | // "timeStamp": "1636382206", 54 | // "hash": "0x07ef689ba048006542b287aa6e89c777a9f6550b01ceac83fd3bef88ead38387", 55 | // "nonce": "2095670", 56 | // "blockHash": "0x3a029015928e4752ace608cd879c83efeca1a3a30dd0c1755ec97aa335813ae1", 57 | // "transactionIndex": "24", 58 | // "from": "0xdccf3b77da55107280bd850ea519df3705d1a75a", 59 | // "to": "0x4e656459ed25bf986eea1196bc1b00665401645d", 60 | // "value": "3873118620000000000", 61 | // "gas": "207128", 62 | // "gasPrice": "10000000000", 63 | // "isError": "0", 64 | // "txreceipt_status": "1", 65 | // "input": "0x", 66 | // "contractAddress": "", 67 | // "cumulativeGasUsed": "1463016", 68 | // "gasUsed": "21000", 69 | // "confirmations": "361409" 70 | // }, 71 | // { 72 | // "blockNumber": "12685304", 73 | // "timeStamp": "1637030116", 74 | // "hash": "0xba2ad55a8cc6126c125a2460cbc27030b4ecb9cce27e8f238fcd71fcf32d6c24", 75 | // "nonce": "155854", 76 | // "blockHash": "0x53a5e395180d31adc534a846b3620690b0bc40237819df209980d0090fd8e8f3", 77 | // "transactionIndex": "41", 78 | // "from": "0x1fbe2acee135d991592f167ac371f3dd893a508b", 79 | // "to": "0x4e656459ed25bf986eea1196bc1b00665401645d", 80 | // "value": "2559805720000000000", 81 | // "gas": "207128", 82 | // "gasPrice": "10000000000", 83 | // "isError": "0", 84 | // "txreceipt_status": "1", 85 | // "input": "0x", 86 | // "contractAddress": "", 87 | // "cumulativeGasUsed": "1224129", 88 | // "gasUsed": "21000", 89 | // "confirmations": "152497" 90 | // } 91 | //] 92 | ``` 93 | 94 | ## License 95 | 96 | > Copyright (C) 2021, Jean-Philippe Monette 97 | > 98 | > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 99 | > 100 | > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 101 | > 102 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 103 | -------------------------------------------------------------------------------- /docs/modules.html: -------------------------------------------------------------------------------- 1 | @jpmonette/bscscan
Options
All
  • Public
  • Public/Protected
  • All
Menu

@jpmonette/bscscan

Legend

  • Type alias
  • Type alias with type parameter
  • Class

Settings

Theme

Generated using TypeDoc

-------------------------------------------------------------------------------- /CODE_OF_CONDUCT_md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | ## 1. Purpose 4 | 5 | A primary goal of `bscscan-ts` is to be inclusive to the largest number of contributors, with the most varied and diverse backgrounds possible. As such, we are committed to providing a friendly, safe and welcoming environment for all, regardless of gender, sexual orientation, ability, ethnicity, socioeconomic status, and religion (or lack thereof). 6 | 7 | This code of conduct outlines our expectations for all those who participate in our community, as well as the consequences for unacceptable behavior. 8 | 9 | We invite all those who participate in `bscscan-ts` to help us create safe and positive experiences for everyone. 10 | 11 | ## 2. Open Source Citizenship 12 | 13 | A supplemental goal of this Code of Conduct is to increase open source citizenship by encouraging participants to recognize and strengthen the relationships between our actions and their effects on our community. 14 | 15 | Communities mirror the societies in which they exist and positive action is essential to counteract the many forms of inequality and abuses of power that exist in society. 16 | 17 | If you see someone who is making an extra effort to ensure our community is welcoming, friendly, and encourages all participants to contribute to the fullest extent, we want to know. 18 | 19 | ## 3. Expected Behavior 20 | 21 | The following behaviors are expected and requested of all community members: 22 | 23 | - Participate in an authentic and active way. In doing so, you contribute to the health and longevity of this community. 24 | - Exercise consideration and respect in your speech and actions. 25 | - Attempt collaboration before conflict. 26 | - Refrain from demeaning, discriminatory, or harassing behavior and speech. 27 | - Be mindful of your surroundings and of your fellow participants. Alert community leaders if you notice a dangerous situation, someone in distress, or violations of this Code of Conduct, even if they seem inconsequential. 28 | - Remember that community event venues may be shared with members of the public; please be respectful to all patrons of these locations. 29 | 30 | ## 4. Unacceptable Behavior 31 | 32 | The following behaviors are considered harassment and are unacceptable within our community: 33 | 34 | - Violence, threats of violence or violent language directed against another person. 35 | - Sexist, racist, homophobic, transphobic, ableist or otherwise discriminatory jokes and language. 36 | - Posting or displaying sexually explicit or violent material. 37 | - Posting or threatening to post other people’s personally identifying information ("doxing"). 38 | - Personal insults, particularly those related to gender, sexual orientation, race, religion, or disability. 39 | - Inappropriate photography or recording. 40 | - Inappropriate physical contact. You should have someone’s consent before touching them. 41 | - Unwelcome sexual attention. This includes, sexualized comments or jokes; inappropriate touching, groping, and unwelcomed sexual advances. 42 | - Deliberate intimidation, stalking or following (online or in person). 43 | - Advocating for, or encouraging, any of the above behavior. 44 | - Sustained disruption of community events, including talks and presentations. 45 | 46 | ## 5. Consequences of Unacceptable Behavior 47 | 48 | Unacceptable behavior from any community member, including sponsors and those with decision-making authority, will not be tolerated. 49 | 50 | Anyone asked to stop unacceptable behavior is expected to comply immediately. 51 | 52 | If a community member engages in unacceptable behavior, the community organizers may take any action they deem appropriate, up to and including a temporary ban or permanent expulsion from the community without warning (and without refund in the case of a paid event). 53 | 54 | ## 6. Reporting Guidelines 55 | 56 | If you are subject to or witness unacceptable behavior, or have any other concerns, please notify a community organizer as soon as possible. contact@jpmonette.net. 57 | 58 | Additionally, community organizers are available to help community members engage with local law enforcement or to otherwise help those experiencing unacceptable behavior feel safe. In the context of in-person events, organizers will also provide escorts as desired by the person experiencing distress. 59 | 60 | ## 7. Addressing Grievances 61 | 62 | If you feel you have been falsely or unfairly accused of violating this Code of Conduct, you should notify Jean-Philippe Monette with a concise description of your grievance. Your grievance will be handled in accordance with our existing governing policies. 63 | 64 | ## 8. Scope 65 | 66 | We expect all community participants (contributors, paid or otherwise; sponsors; and other guests) to abide by this Code of Conduct in all community venues–online and in-person–as well as in all one-on-one communications pertaining to community business. 67 | 68 | This code of conduct and its related procedures also applies to unacceptable behavior occurring outside the scope of community activities when such behavior has the potential to adversely affect the safety and well-being of community members. 69 | 70 | ## 9. Contact info 71 | 72 | contact@jpmonette.net 73 | 74 | ## 10. License and attribution 75 | 76 | This Code of Conduct is distributed under a [Creative Commons Attribution-ShareAlike license](http://creativecommons.org/licenses/by-sa/3.0/). 77 | 78 | Portions of text derived from the [Django Code of Conduct](https://www.djangoproject.com/conduct/) and the [Geek Feminism Anti-Harassment Policy](http://geekfeminism.wikia.com/wiki/Conference_anti-harassment/Policy). 79 | 80 | Retrieved on November 22, 2016 from [http://citizencodeofconduct.org/](http://citizencodeofconduct.org/) 81 | -------------------------------------------------------------------------------- /src/__tests__/modules/__snapshots__/accounts.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`account should getBalance 1`] = `"1921440981086393507806711"`; 4 | 5 | exports[`account should getBalanceMulti 1`] = ` 6 | Array [ 7 | Object { 8 | "account": "0x515b72ed8a97f42c568d6a143232775018f133c8", 9 | "balance": "1921270037723443507806711", 10 | }, 11 | Object { 12 | "account": "0x161ba15a5f335c9f06bb5bbb0a9ce14076fbb645", 13 | "balance": "1627060201835648279950872", 14 | }, 15 | ] 16 | `; 17 | 18 | exports[`account should getMinedBlocks - blocks found 1`] = ` 19 | Array [ 20 | Object { 21 | "blockNumber": "12837584", 22 | "blockReward": "647708965667033920", 23 | "timeStamp": "1637509278", 24 | }, 25 | Object { 26 | "blockNumber": "12837563", 27 | "blockReward": "507184284612347890", 28 | "timeStamp": "1637509215", 29 | }, 30 | Object { 31 | "blockNumber": "12837542", 32 | "blockReward": "565437075463792362", 33 | "timeStamp": "1637509152", 34 | }, 35 | Object { 36 | "blockNumber": "12837521", 37 | "blockReward": "0", 38 | "timeStamp": "1637509089", 39 | }, 40 | ] 41 | `; 42 | 43 | exports[`account should getMinedBlocks - error 1`] = `[Error: API Key Not Found - ]`; 44 | 45 | exports[`account should getMinedBlocks - no block 1`] = `Array []`; 46 | 47 | exports[`account should getTokenNFTTx 1`] = ` 48 | Array [ 49 | Object { 50 | "blockHash": "0xdf0e6157fab1d82b530f487f857d902209074ee816324e802952d256ad00cb6f", 51 | "blockNumber": "11998587", 52 | "confirmations": "838914", 53 | "contractAddress": "0xc0bfe67cedc9fe042f335258eb75b9e1baaf1a5d", 54 | "cumulativeGasUsed": "50420346", 55 | "from": "0xc0ecdbffbe14e69438ef0f06c16842c88573f564", 56 | "gas": "111424", 57 | "gasPrice": "5000000000", 58 | "gasUsed": "81424", 59 | "hash": "0x50a2e22db4df52d73f2743f06152be86fb3b600646f72e9e7e7abd415531f419", 60 | "input": "deprecated", 61 | "nonce": "379", 62 | "timeStamp": "1634923334", 63 | "to": "0x515b72ed8a97f42c568d6a143232775018f133c8", 64 | "tokenDecimal": "0", 65 | "tokenID": "260", 66 | "tokenName": "TTK Hero", 67 | "tokenSymbol": "TTKHero", 68 | "transactionIndex": "336", 69 | }, 70 | ] 71 | `; 72 | 73 | exports[`account should getTokenTx 1`] = ` 74 | Array [ 75 | Object { 76 | "blockHash": "0x868ceda2b8063d0f40056446ff5fab3cba494b3a3752bf7cd6297297cf0b0740", 77 | "blockNumber": "8527363", 78 | "confirmations": "4309633", 79 | "contractAddress": "0xc1ed07a64f69ba3658e227a76d962218519c147a", 80 | "cumulativeGasUsed": "16012394", 81 | "from": "0xd152f549545093347a162dce210e7293f1452150", 82 | "gas": "8129776", 83 | "gasPrice": "5000000000", 84 | "gasUsed": "8125393", 85 | "hash": "0xe41ccda7b52e8720ea5663bfc19e1c6d912b2c67ecd0be29294cce01d5ef2bdd", 86 | "input": "deprecated", 87 | "nonce": "112", 88 | "timeStamp": "1624391825", 89 | "to": "0x515b72ed8a97f42c568d6a143232775018f133c8", 90 | "tokenDecimal": "18", 91 | "tokenName": "OVRswap.com", 92 | "tokenSymbol": "OVR", 93 | "transactionIndex": "57", 94 | "value": "1989000000000000000000", 95 | }, 96 | Object { 97 | "blockHash": "0xa653a8587e05b4faeca01da1430a141dd74e58444ba94205298d95b35754277e", 98 | "blockNumber": "8534601", 99 | "confirmations": "4302395", 100 | "contractAddress": "0x1deb61e41f337b04660eab59a34ad5e39afe9348", 101 | "cumulativeGasUsed": "6707064", 102 | "from": "0x9ed60f5a914ef064e7abf0643b1b47b3e8b568e8", 103 | "gas": "51189", 104 | "gasPrice": "5000000000", 105 | "gasUsed": "51189", 106 | "hash": "0x5fe7553d393baec7876792abba532f3b97d60d841cb15674d5b55cece7d03242", 107 | "input": "deprecated", 108 | "nonce": "36", 109 | "timeStamp": "1624413715", 110 | "to": "0x515b72ed8a97f42c568d6a143232775018f133c8", 111 | "tokenDecimal": "18", 112 | "tokenName": "EAO", 113 | "tokenSymbol": "EAO", 114 | "transactionIndex": "49", 115 | "value": "160000000000000000000", 116 | }, 117 | ] 118 | `; 119 | 120 | exports[`account should getTxList 1`] = ` 121 | Array [ 122 | Object { 123 | "blockHash": "0xfb8a6a69ddc2e72aae9be480d3162f041578fee6cdbfc0e175cb3d5422df9b6e", 124 | "blockNumber": "8200395", 125 | "confirmations": "4637006", 126 | "contractAddress": "", 127 | "cumulativeGasUsed": "2452470", 128 | "from": "0x8894e0a0c962cb723c1976a4421c95949be2d4e3", 129 | "gas": "21000", 130 | "gasPrice": "10000000000", 131 | "gasUsed": "21000", 132 | "hash": "0xe9a602f83a4e9592cd3b08ff0ec99b65842b66acf71325b163f802d764915679", 133 | "input": "0x", 134 | "isError": "0", 135 | "nonce": "17", 136 | "timeStamp": "1623403230", 137 | "to": "0x515b72ed8a97f42c568d6a143232775018f133c8", 138 | "transactionIndex": "11", 139 | "txreceipt_status": "1", 140 | "value": "1000000000000000000000", 141 | }, 142 | Object { 143 | "blockHash": "0x8f350abfaf636fd998ba054c7edf9d351b01e317592403185ee26901db555dd3", 144 | "blockNumber": "8400190", 145 | "confirmations": "4437211", 146 | "contractAddress": "", 147 | "cumulativeGasUsed": "3390501", 148 | "from": "0x515b72ed8a97f42c568d6a143232775018f133c8", 149 | "gas": "21000", 150 | "gasPrice": "10000000000", 151 | "gasUsed": "21000", 152 | "hash": "0x96f03c131e7a4e159a83131afbfe5f985be105a6593a144e2034d8ffde2c6dcf", 153 | "input": "0x", 154 | "isError": "0", 155 | "nonce": "0", 156 | "timeStamp": "1624008263", 157 | "to": "0xb2923dc4096e1ec1401ff4febd99c2f6b5315bf4", 158 | "transactionIndex": "13", 159 | "txreceipt_status": "1", 160 | "value": "1411454740000000000", 161 | }, 162 | ] 163 | `; 164 | 165 | exports[`account should getTxListInternal 1`] = ` 166 | Array [ 167 | Object { 168 | "blockNumber": "10628250", 169 | "contractAddress": "", 170 | "errCode": "", 171 | "from": "0xf392c128acbfd7966f1cf08deb11a79cf12b3883", 172 | "gas": "0", 173 | "gasUsed": "0", 174 | "hash": "0xc6963be01d4e718ccb57fac77eeb9470079f68c8ded39d691c8628e46b48f22d", 175 | "input": "", 176 | "isError": "0", 177 | "timeStamp": "1630779994", 178 | "to": "0x515b72ed8a97f42c568d6a143232775018f133c8", 179 | "traceId": "0_1", 180 | "type": "call", 181 | "value": "112310000000000", 182 | }, 183 | ] 184 | `; 185 | -------------------------------------------------------------------------------- /src/__tests__/data/accounts.ts: -------------------------------------------------------------------------------- 1 | export const accountResponses: Record = { 2 | balance: { 3 | status: "1", 4 | message: "OK", 5 | result: "1921440981086393507806711", 6 | }, 7 | balancemulti: { 8 | status: "1", 9 | message: "OK", 10 | result: [ 11 | { account: "0x515b72ed8a97f42c568d6a143232775018f133c8", balance: "1921270037723443507806711" }, 12 | { account: "0x161ba15a5f335c9f06bb5bbb0a9ce14076fbb645", balance: "1627060201835648279950872" }, 13 | ], 14 | }, 15 | txlist: { 16 | status: "1", 17 | message: "OK", 18 | result: [ 19 | { 20 | blockNumber: "8200395", 21 | timeStamp: "1623403230", 22 | hash: "0xe9a602f83a4e9592cd3b08ff0ec99b65842b66acf71325b163f802d764915679", 23 | nonce: "17", 24 | blockHash: "0xfb8a6a69ddc2e72aae9be480d3162f041578fee6cdbfc0e175cb3d5422df9b6e", 25 | transactionIndex: "11", 26 | from: "0x8894e0a0c962cb723c1976a4421c95949be2d4e3", 27 | to: "0x515b72ed8a97f42c568d6a143232775018f133c8", 28 | value: "1000000000000000000000", 29 | gas: "21000", 30 | gasPrice: "10000000000", 31 | isError: "0", 32 | txreceipt_status: "1", 33 | input: "0x", 34 | contractAddress: "", 35 | cumulativeGasUsed: "2452470", 36 | gasUsed: "21000", 37 | confirmations: "4637006", 38 | }, 39 | { 40 | blockNumber: "8400190", 41 | timeStamp: "1624008263", 42 | hash: "0x96f03c131e7a4e159a83131afbfe5f985be105a6593a144e2034d8ffde2c6dcf", 43 | nonce: "0", 44 | blockHash: "0x8f350abfaf636fd998ba054c7edf9d351b01e317592403185ee26901db555dd3", 45 | transactionIndex: "13", 46 | from: "0x515b72ed8a97f42c568d6a143232775018f133c8", 47 | to: "0xb2923dc4096e1ec1401ff4febd99c2f6b5315bf4", 48 | value: "1411454740000000000", 49 | gas: "21000", 50 | gasPrice: "10000000000", 51 | isError: "0", 52 | txreceipt_status: "1", 53 | input: "0x", 54 | contractAddress: "", 55 | cumulativeGasUsed: "3390501", 56 | gasUsed: "21000", 57 | confirmations: "4437211", 58 | }, 59 | ], 60 | }, 61 | txlistinternal: { 62 | status: "1", 63 | message: "OK", 64 | result: [ 65 | { 66 | blockNumber: "10628250", 67 | timeStamp: "1630779994", 68 | hash: "0xc6963be01d4e718ccb57fac77eeb9470079f68c8ded39d691c8628e46b48f22d", 69 | from: "0xf392c128acbfd7966f1cf08deb11a79cf12b3883", 70 | to: "0x515b72ed8a97f42c568d6a143232775018f133c8", 71 | value: "112310000000000", 72 | contractAddress: "", 73 | input: "", 74 | type: "call", 75 | gas: "0", 76 | gasUsed: "0", 77 | traceId: "0_1", 78 | isError: "0", 79 | errCode: "", 80 | }, 81 | ], 82 | }, 83 | tokentx: { 84 | status: "1", 85 | message: "OK", 86 | result: [ 87 | { 88 | blockNumber: "8527363", 89 | timeStamp: "1624391825", 90 | hash: "0xe41ccda7b52e8720ea5663bfc19e1c6d912b2c67ecd0be29294cce01d5ef2bdd", 91 | nonce: "112", 92 | blockHash: "0x868ceda2b8063d0f40056446ff5fab3cba494b3a3752bf7cd6297297cf0b0740", 93 | from: "0xd152f549545093347a162dce210e7293f1452150", 94 | contractAddress: "0xc1ed07a64f69ba3658e227a76d962218519c147a", 95 | to: "0x515b72ed8a97f42c568d6a143232775018f133c8", 96 | value: "1989000000000000000000", 97 | tokenName: "OVRswap.com", 98 | tokenSymbol: "OVR", 99 | tokenDecimal: "18", 100 | transactionIndex: "57", 101 | gas: "8129776", 102 | gasPrice: "5000000000", 103 | gasUsed: "8125393", 104 | cumulativeGasUsed: "16012394", 105 | input: "deprecated", 106 | confirmations: "4309633", 107 | }, 108 | { 109 | blockNumber: "8534601", 110 | timeStamp: "1624413715", 111 | hash: "0x5fe7553d393baec7876792abba532f3b97d60d841cb15674d5b55cece7d03242", 112 | nonce: "36", 113 | blockHash: "0xa653a8587e05b4faeca01da1430a141dd74e58444ba94205298d95b35754277e", 114 | from: "0x9ed60f5a914ef064e7abf0643b1b47b3e8b568e8", 115 | contractAddress: "0x1deb61e41f337b04660eab59a34ad5e39afe9348", 116 | to: "0x515b72ed8a97f42c568d6a143232775018f133c8", 117 | value: "160000000000000000000", 118 | tokenName: "EAO", 119 | tokenSymbol: "EAO", 120 | tokenDecimal: "18", 121 | transactionIndex: "49", 122 | gas: "51189", 123 | gasPrice: "5000000000", 124 | gasUsed: "51189", 125 | cumulativeGasUsed: "6707064", 126 | input: "deprecated", 127 | confirmations: "4302395", 128 | }, 129 | ], 130 | }, 131 | tokennfttx: { 132 | status: "1", 133 | message: "OK", 134 | result: [ 135 | { 136 | blockNumber: "11998587", 137 | timeStamp: "1634923334", 138 | hash: "0x50a2e22db4df52d73f2743f06152be86fb3b600646f72e9e7e7abd415531f419", 139 | nonce: "379", 140 | blockHash: "0xdf0e6157fab1d82b530f487f857d902209074ee816324e802952d256ad00cb6f", 141 | from: "0xc0ecdbffbe14e69438ef0f06c16842c88573f564", 142 | contractAddress: "0xc0bfe67cedc9fe042f335258eb75b9e1baaf1a5d", 143 | to: "0x515b72ed8a97f42c568d6a143232775018f133c8", 144 | tokenID: "260", 145 | tokenName: "TTK Hero", 146 | tokenSymbol: "TTKHero", 147 | tokenDecimal: "0", 148 | transactionIndex: "336", 149 | gas: "111424", 150 | gasPrice: "5000000000", 151 | gasUsed: "81424", 152 | cumulativeGasUsed: "50420346", 153 | input: "deprecated", 154 | confirmations: "838914", 155 | }, 156 | ], 157 | }, 158 | getminedblocks: { 159 | success: { 160 | status: "1", 161 | message: "OK", 162 | result: [ 163 | { blockNumber: "12837584", timeStamp: "1637509278", blockReward: "647708965667033920" }, 164 | { blockNumber: "12837563", timeStamp: "1637509215", blockReward: "507184284612347890" }, 165 | { blockNumber: "12837542", timeStamp: "1637509152", blockReward: "565437075463792362" }, 166 | { blockNumber: "12837521", timeStamp: "1637509089", blockReward: "0" }, 167 | ], 168 | }, 169 | noBlock: { 170 | status: "0", 171 | message: "No transactions found", 172 | result: [], 173 | }, 174 | error: { 175 | status: "0", 176 | message: "API Key Not Found", 177 | result: [], 178 | }, 179 | }, 180 | }; 181 | -------------------------------------------------------------------------------- /docs/modules/typings_transactions.html: -------------------------------------------------------------------------------- 1 | typings/transactions | @jpmonette/bscscan
Options
All
  • Public
  • Public/Protected
  • All
Menu

Module typings/transactions

Index

Type aliases

GetTxReceiptStatusRequest

GetTxReceiptStatusRequest: { txhash: string }

Type declaration

  • txhash: string

GetTxReceiptStatusResponse

GetTxReceiptStatusResponse: { status: "0" | "1" }

Type declaration

  • status: "0" | "1"

Legend

  • Type alias
  • Type alias with type parameter
  • Class

Settings

Theme

Generated using TypeDoc

-------------------------------------------------------------------------------- /docs/modules/typings_stats.html: -------------------------------------------------------------------------------- 1 | typings/stats | @jpmonette/bscscan
Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Type aliases

GetBNBLastPriceResponse

GetBNBLastPriceResponse: { ethbtc: string; ethbtc_timestamp: string; ethusd: string; ethusd_timestamp: string }

Type declaration

  • ethbtc: string
  • ethbtc_timestamp: string
  • ethusd: string
  • ethusd_timestamp: string

GetBNBTotalSupplyResponse

GetBNBTotalSupplyResponse: string

GetValidatorsResponse

GetValidatorsResponse: GetValidatorsResponseItem[]

GetValidatorsResponseItem

GetValidatorsResponseItem: { validatorAddress: string; validatorName: string; validatorStatus: string; validatorVotingPower: string; validatorVotingPowerProportion: string }

Type declaration

  • validatorAddress: string
  • validatorName: string
  • validatorStatus: string
  • validatorVotingPower: string
  • validatorVotingPowerProportion: string

Legend

  • Type alias
  • Type alias with type parameter
  • Class

Settings

Theme

Generated using TypeDoc

-------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | @jpmonette/bscscan
Options
All
  • Public
  • Public/Protected
  • All
Menu

@jpmonette/bscscan

@jpmonette/bscscan

2 | 3 |

@jpmonette/bscscan - Explore the Binance Smart Chain using TypeScript and JavaScript

4 | 5 |

6 | Build Status Coverage Status npm version Tested with Jest License: MIT 7 |

8 | 9 |
10 |

👩🏻‍💻 Developer Ready: Interact with the BscScan API in no time!

11 |

💪🏼 Strongly Typed: Developed using TypeScript.

12 |

🔒 Battleproof: Tested using Jest.

13 | 14 | 15 |

Getting Started

16 |
17 | 18 | 19 |

Installation

20 |
21 |
$ yarn add @jpmonette/bscscan
22 | 
23 | 24 | 25 |

Usage

26 |
27 | 28 | 29 |

Import & Initialize

30 |
31 |
import { BscScan } from "@jpmonette/bscscan";

const client = new BscScan({ apikey: "api-key" }); 32 |
33 | 34 | 35 |

Get Account Balance

36 |
37 |
const balance = await client.accounts.getBalance({ address: "0x4e656459ed25bf986eea1196bc1b00665401645d" });

console.log(balance);
// 13305527100000000000 38 |
39 | 40 | 41 |

Get Transaction List

42 |
43 |
const txlist = await client.accounts.getTxList({ address: "0x4e656459ed25bf986eea1196bc1b00665401645d" });

console.log(txlist);
//[
// {
// "blockNumber": "12476392",
// "timeStamp": "1636382206",
// "hash": "0x07ef689ba048006542b287aa6e89c777a9f6550b01ceac83fd3bef88ead38387",
// "nonce": "2095670",
// "blockHash": "0x3a029015928e4752ace608cd879c83efeca1a3a30dd0c1755ec97aa335813ae1",
// "transactionIndex": "24",
// "from": "0xdccf3b77da55107280bd850ea519df3705d1a75a",
// "to": "0x4e656459ed25bf986eea1196bc1b00665401645d",
// "value": "3873118620000000000",
// "gas": "207128",
// "gasPrice": "10000000000",
// "isError": "0",
// "txreceipt_status": "1",
// "input": "0x",
// "contractAddress": "",
// "cumulativeGasUsed": "1463016",
// "gasUsed": "21000",
// "confirmations": "361409"
// },
// {
// "blockNumber": "12685304",
// "timeStamp": "1637030116",
// "hash": "0xba2ad55a8cc6126c125a2460cbc27030b4ecb9cce27e8f238fcd71fcf32d6c24",
// "nonce": "155854",
// "blockHash": "0x53a5e395180d31adc534a846b3620690b0bc40237819df209980d0090fd8e8f3",
// "transactionIndex": "41",
// "from": "0x1fbe2acee135d991592f167ac371f3dd893a508b",
// "to": "0x4e656459ed25bf986eea1196bc1b00665401645d",
// "value": "2559805720000000000",
// "gas": "207128",
// "gasPrice": "10000000000",
// "isError": "0",
// "txreceipt_status": "1",
// "input": "0x",
// "contractAddress": "",
// "cumulativeGasUsed": "1224129",
// "gasUsed": "21000",
// "confirmations": "152497"
// }
//] 44 |
45 | 46 | 47 |

License

48 |
49 |
50 |

Copyright (C) 2021, Jean-Philippe Monette contact@jpmonette.net

51 |

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

52 |

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

53 |

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

54 |
55 |

Legend

  • Type alias
  • Type alias with type parameter
  • Class

Settings

Theme

Generated using TypeDoc

-------------------------------------------------------------------------------- /docs/classes/modules_transactions.Transactions.html: -------------------------------------------------------------------------------- 1 | Transactions | @jpmonette/bscscan
Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Transactions

Index

Constructors

Properties

Methods

Constructors

constructor

Properties

Private client

client: BscScan
5 |

Represents the BscScan client

6 |
memberof

Transactions

7 |

Methods

Private do

  • do(action: string, opts: Record<string, any>): Promise<any>

getTxReceiptStatus

Legend

  • Class
  • Constructor
  • Method
  • Type alias
  • Type alias with type parameter
  • Private property
  • Private method

Settings

Theme

Generated using TypeDoc

-------------------------------------------------------------------------------- /docs/classes/modules_stats.Stats.html: -------------------------------------------------------------------------------- 1 | Stats | @jpmonette/bscscan
Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Stats

Index

Constructors

constructor

Properties

Private client

client: BscScan
5 |

Represents the BscScan client

6 |
memberof

Stats

7 |

Methods

Private do

  • do(action: string, opts?: Record<string, any>): Promise<any>
  • Parameters

    • action: string
    • Optional opts: Record<string, any>

    Returns Promise<any>

getBNBLastPrice

getBNBTotalSupply

  • getBNBTotalSupply(): Promise<string>

getValidators

Legend

  • Class
  • Constructor
  • Method
  • Type alias
  • Type alias with type parameter
  • Private property
  • Private method

Settings

Theme

Generated using TypeDoc

-------------------------------------------------------------------------------- /docs/classes/client.BscScan.html: -------------------------------------------------------------------------------- 1 | BscScan | @jpmonette/bscscan
Options
All
  • Public
  • Public/Protected
  • All
Menu
2 |

A BscScan API client

3 |

Hierarchy

  • BscScan

Index

Constructors

constructor

Properties

accounts

accounts: Accounts

apikey

apikey: undefined | string

baseUrl

baseUrl: string

contracts

contracts: Contracts

stats

stats: Stats

transactions

transactions: Transactions

Methods

do

  • do<T>(request: Request): Promise<T>
  • 7 |

    Executes an HTTP request

    8 |
    memberof

    BscScan

    9 |

    Type parameters

    • T

    Parameters

    • request: Request

    Returns Promise<T>

newRequest

  • newRequest(method?: string, module: string, action: string, opts?: Record<string, any>): Request
  • 10 |

    Creates a new HTTP request

    11 |
    memberof

    BscScan

    12 |

    Parameters

    • method: string = "GET"
    • module: string
    • action: string
    • opts: Record<string, any> = {}

    Returns Request

query

  • query(module: string, action: string, opts?: Record<string, any>): Promise<any>
  • 13 |

    Executes a simplified API query

    14 |
    memberof

    BscScan

    15 |

    Parameters

    • module: string
    • action: string
    • opts: Record<string, any> = {}

    Returns Promise<any>

Legend

  • Class
  • Constructor
  • Property
  • Method
  • Type alias
  • Type alias with type parameter

Settings

Theme

Generated using TypeDoc

-------------------------------------------------------------------------------- /docs/classes/modules_contracts.Contracts.html: -------------------------------------------------------------------------------- 1 | Contracts | @jpmonette/bscscan
Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Contracts

Index

Constructors

constructor

Properties

Private client

client: BscScan
5 |

Represents the BscScan client

6 |
memberof

Contracts

7 |

Methods

checkProxyVerification

Private do

  • do(action: string, opts: Record<string, any>): Promise<any>

getAbi

getSourceCode

verifyProxyContract

verifySourceCode

Legend

  • Class
  • Constructor
  • Method
  • Type alias
  • Type alias with type parameter
  • Private property
  • Private method

Settings

Theme

Generated using TypeDoc

-------------------------------------------------------------------------------- /docs/classes/modules_accounts.Accounts.html: -------------------------------------------------------------------------------- 1 | Accounts | @jpmonette/bscscan
Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Accounts

Index

Constructors

constructor

Properties

Private client

client: BscScan
5 |

Represents the BscScan client

6 |
memberof

Accounts

7 |

Methods

Private do

  • do(action: string, opts: Record<string, any>): Promise<any>

getBalance

getBalanceMulti

getMinedBlocks

getTokenNFTTx

getTokenTx

getTxList

getTxListInternal

Legend

  • Class
  • Constructor
  • Method
  • Type alias
  • Type alias with type parameter
  • Private property
  • Private method

Settings

Theme

Generated using TypeDoc

--------------------------------------------------------------------------------