1.0.12 • Published 1 year ago

ng-blockchainx v1.0.12

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

NgBlockchainX

Find Complete documentation here Open docs

This library was generated with Angular CLI version 12.2.0.

Meta mask service

// import Metamask service on component in which you need
import { MetaMaskService } from "ng-blockchainx";

// add metamask service as DI ( dependency injection )
constructor(private metaMaskService: MetaMaskService) {}

To connect metamask wallet

this.metaMaskService.connectMetaMask()
.then((response:any) => {
    // DO your success logic here
})
.catch((error:any) => {
    // DO your failure logic here
});

To change active network on metamask wallet

// 'chainId = chain id of the network which to be active
this.metaMaskService.changeNetwork('chainID')
.then((response:any) => {
    // DO your success logic here
})
.catch((error:any) => {
    // DO your failure logic here
});
export interface Response {
    status: boolean;
    code: number;
    message: string;
    data: Data | undefined | any;
}

this.metaMaskService.connectionListener.subscribe((response:Response) => {
    console.log(response);
    // Do your logic here
});
Response codeMessageDescription
250511Metamask not installed on browser
250512Metamask not connected
250500Un expected error
250601Metamask connected successfully
250609Service init successJust ignore this event
250610Chain changed
250611account changed
250612metamask connection closed

Web3 service

If you are using Angular version >11 and run into an issue building. This is because polyfills are not included in the newest version of Angular.

  • Install the required dependencies within your angular project:
npm install --save-dev crypto-browserify next-tick stream-browserify assert stream-http https-browserify os-browserify
  • Within tsconfig.json add the following paths in compilerOptions so Webpack can get the correct dependencies
{
    "compilerOptions": {
        "paths" : {
        "crypto": ["./node_modules/crypto-browserify"],
        "stream": ["./node_modules/stream-browserify"],
        "assert": ["./node_modules/assert"],
        "http": ["./node_modules/stream-http"],
        "https": ["./node_modules/https-browserify"],
        "os": ["./node_modules/os-browserify"],
    }
}
  • Add the following lines to polyfills.ts file:
import { Buffer } from 'buffer';

(window as any).global = window;
global.Buffer = Buffer;
global.process = {
    env: { DEBUG: undefined },
    version: '',
    nextTick: require('next-tick')
} as any;
  • Create webpack.config.js file on root path and add below code
{
    resolve: {
        fallback: {
            url: require.resolve("url/")
        }
    }
}

after run npm install url

Once above setup done add below code into the component where you need web3service

// import Web3Service on component in which you need by adding below line
import { Web3Service } from "ng-blockchainx";

// add metamask service as DI ( dependency injection )
constructor(private web3Service: Web3Service) {}
1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.12

1 year ago

1.0.5

1 year ago

1.0.4

2 years ago

1.0.2

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.1

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.0-watch

2 years ago