npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@scalingparrots/dapp-angular-lib

v0.4.4

Published

An angular library for creating WEB3 applications

Downloads

156

Readme

Dapp Angular Lib

About

This library is supposed to help the integration of web3 "standard" services.

Features 🚀

🚀 Integrate it into your existing dApp with a few lines of code 🚀 Supports WalletConnect, Metamask and Binance Chain Wallet 🚀 Ready to use services to switch network and add new token to wallet 🚀 Ready to use services to read and write from smart contracts 🚀 Exportable chains list with providers info 🚀 Supports all major browsers 🚀 Fully customisable, style it as you want, support whatever tokens you want and much more 🚀 Fully typescript supported

Live demo

You can view a live demo here.

Installing

npm

$ npm install @scalingparrots/dapp-angular-lib

Warnings running on angular 10 +

You have to update your polyfills.ts file adding this:

(window as any).global = window;
global.Buffer = global.Buffer || require("buffer").Buffer;
global.process = require("process");

Usage

It is very simple to get dapp angular lib up and running, below is a simple example in how to get it working.

your.module.ts

You need to import the DappAngularLibModule into your module file, all you need to do is insert DappAngularLibModule into your imports array.

import { DappAngularLibModule } from "dapp-angular-lib";
import { AppComponent } from "./app.component";
import { YourComponent } from "./your.component";

@NgModule({
  declarations: [YourComponent],
  imports: [DappAngularLibModule],
  providers: [],
  bootstrap: [AppComponent],
})
export class YourModule {}

your.component.ts

Init network and check wallet already connected, check right network connect otherwise switch to the primary one.

import { Component, OnInit } from "@angular/core";
import {
  ChainId,
  NETWORK_INFO,
  NetworkService,
  WalletService,
} from "dapp-angular-lib";

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.scss"],
})
export class YourComponent implements OnInit {
  primary_network = NETWORK_INFO[ChainId.BSC];
  supported_network = [
    NETWORK_INFO[ChainId.BSC],
    NETWORK_INFO[ChainId.Avalanche],
    NETWORK_INFO[ChainId.Palm],
    NETWORK_INFO[ChainId.Polygon],
  ];

  constructor(
    private _walletService: WalletService,
    private _networkService: NetworkService
  ) {}

  /**
   * On load
   */
  ngOnInit(): void {
    // init network necessary
    this._walletService.initNetwork(this.primary_network);

    // check account
    this.getProvider()
      // check network only if needed
      .then((_) => this._networkService.checkNetwork(this.primary_network));
  }

  async getProvider(): Promise<void> {
    await this._walletService.getWebProvider();
  }

  async disconnectWallet(): Promise<void> {
    await this._walletService.disconnectWallet();
  }
}

your.component.ts

Connect wallet. The type you need to pass in the connectWallet() function has to be one of this: ["metamask", "coinbase", "binance", "connectWallet"]

import { Component } from "@angular/core";
import { WalletService } from "dapp-angular-lib";

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.scss"],
})
export class YourComponent {
  constructor(private _walletService: WalletService) {}

  connectWallet(type: string) {
    this._walletService.connectWallet(type);
  }
}

your.component.ts

Switch network. The network you need to pass in the switchNetwork() function has to be an element of NETWORK_INFO

import { Component } from "@angular/core";
import { NetworkService } from "dapp-angular-lib";

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.scss"],
})
export class YourComponent {
  constructor(private _networkService: NetworkService) {}

  switchNetwork(network: any): void {
    this._networkService.changeNetwork(network);
  }
}

your.component.ts

Get balance wallet

import { Component } from "@angular/core";
import { WalletService } from "dapp-angular-lib";

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.scss"],
})
export class YourComponent {
  constructor(private _walletService: WalletService) {}

  getBalanceWallet(rpc: string, wallet: string) {
    this._walletService.getWalletBalance(rpc, wallet);
  }
}

your.component.ts

Contract calls

import { Component, OnInit } from "@angular/core";
import { ChainId, NETWORK_INFO, ContractService } from "dapp-angular-lib";

const abi = require("../../../core/abi/erc20.abi.json");

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.scss"],
})
export class YourComponent implements OnInit {
  constructor(
    private _contractService: ContractService,
    private _messageService: MessageService
  ) {}

  ngOnInit(): void {
    // example of read contract
    this.readTotalBurn();

    // example of write contract
    this.approve("0x0000000000000000000000000000000000000000", 100);
  }

  async readTotalBurn() {
    try {
      const totalBurn = await this._contractService.readContract(
        "0x0000000000000000000000000000000000000000",
        NETWORK_INFO[ChainId.BSC].rpcUrls[0],
        abi,
        "totalBurn"
      );

      this._messageService.showMessage(
        "Total burn: " + totalBurn.toLocaleString()
      );
    } catch (error: any) {
      this._messageService.showMessage(
        "Total burn " + error.message,
        3000,
        "error"
      );
    }
  }

  async approve(spender: string, amount: number) {
    const decimals = 18;
    const amountFormatted = BigNumber.from(amount).mul(
      BigNumber.from(10).pow(decimals)
    );

    try {
      const tx = await this._contractService.writeContract(
        "0x0000000000000000000000000000000000000000",
        abi,
        "approve",
        [spender, amountFormatted]
      );

      this._messageService.showMessage("Approve: " + tx);
    } catch (error: any) {
      this._messageService.showMessage(
        "Approve " + error.message,
        3000,
        "error"
      );
    }
  }
}