Skip to content

Blockscout Client for any Front-end framework based on JavaScript

License

Notifications You must be signed in to change notification settings

aaop3734/blockscout-cli

Repository files navigation

NPM Version NPM Downloads Minified Size FOSSA Status

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.

License

FOSSA Status

About

Blockscout Client for any Front-end framework based on JavaScript

Topics

Resources

License

Stars

Watchers

Forks