blockscout-cli
v0.1.6
Published
Blockscout Client for any Framework base on NodeJS
Downloads
261
Maintainers
Readme
BlockScout-CLI
A TypeScript/JavaScript client that utilizes axios to make HTTP requests to the BlockScout API for any Front-end framework based on JavaScript.
📚 Install
npm install blockscout-cli
or
yarn add blockscout-cli
🚀 Front-end Examples
⚙️ Configuration
In file blockscout-cli.service.ts
import { Configuration, DefaultApi } from 'blockscout-cli'
const config = new Configuration({
basePath: 'https://eth.blockscout.com/api/v2/',
})
const BlockscoutService = new DefaultApi(config)
export default BlockscoutService
🔨 Usage
import React from 'react'
import BlockscoutService from '@/services/blockscout-cli.service'
const blockScoutSearch = async (q: string | undefined) => {
const result = await BlockscoutService.search(q)
return result.data
}
function Home() {
const onClick = async () => {
const result = await blockScoutSearch('USDT')
console.log(result)
}
return (
<>
<button onClick={onClick}>Search</button>
</>
)
}
export default Home
🚀 Back-end Examples (With NestJS)
⚙️ Configuration
In file blockscout.service.ts
import { Injectable } from '@nestjs/common'
import { Configuration, DefaultApi } from 'blockscout-cli'
@Injectable()
export class BlockscoutService extends DefaultApi {
constructor() {
super(
new Configuration({
basePath: 'https://eth.blockscout.com/api/v2',
}),
)
}
}
In file app.module.ts
import { Global, Module } from '@nestjs/common'
import { AppController } from './app.controller'
import { AppService } from './app.service'
import { BlockscoutService } from './blockscout.service'
@Global()
@Module({
providers: [BlockscoutService],
exports: [BlockscoutService],
})
export class GlobalModule {}
@Module({
imports: [GlobalModule],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
🔨 Usage
import { Injectable } from '@nestjs/common'
import { BlockscoutService } from './blockscout.service'
@Injectable()
export class AppService {
constructor(private blockscoutService: BlockscoutService) {}
async getHomeStarts() {
try {
const { data } = await this.blockscoutService.getStats()
console.log(data)
return data
} catch (e) {
console.log(e)
}
}
}
🖲️ Roadmap
| Feature | Status | | -------------------------------- | :----: | | NextJS + Tanstack Query | ✅ | | React + Tanstack Query | ✅ | | NodeJS with ES Module + CommonJS | ✅️ | | Strict Types Response | ✅ | | Strict Types Payload | ⚠️ |
!!! Note: Typescript Strict now is only with response.
- Types is base on Blockscout front-end. I modified to adapt with api-docs
example: eth blockscout scan