GithubHelp home page GithubHelp logo

aaop3734 / blockscout-cli Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 139 KB

Blockscout Client for any Front-end framework based on JavaScript

License: MIT License

TypeScript 100.00%
blockchain-technology blockscout blockscout-client

blockscout-cli's Introduction

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

blockscout-cli's People

Contributors

aaop3734 avatar danialdinh957 avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

fossabot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.