# ng-blockchainx

> Find Complete documentation here [Open docs ](https://blockchainxtech.github.io/ng-blockchain-x/docs/intro)

Latest version **1.0.12** (published 2023-01-30) · 0 weekly downloads

## Install

```sh
npm install ng-blockchainx
pnpm add ng-blockchainx
yarn add ng-blockchainx
bun add ng-blockchainx
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.12 |
| Published | 2023-01-30 |
| First published | 2022-04-28 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 2.7 MB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | sivabharathy |
| Maintainers | sparkout_tech |

## Links

- npm: https://www.npmjs.com/package/ng-blockchainx
- Repository: https://github.com/Blockchainxtech/ng-blockchain-x
- Homepage: https://github.com/Blockchainxtech/ng-blockchain-x#readme
- Issues: https://github.com/Blockchainxtech/ng-blockchain-x/issues
- npm.io page: https://npm.io/package/ng-blockchainx

## Dependencies (5)

- [web3](https://npm.io/package/web3.md) 1.2.11
- [tslib](https://npm.io/package/tslib.md) ^2.3.0
- [@walletconnect/client](https://npm.io/package/@walletconnect/client.md) ^1.7.8
- [@walletconnect/qrcode-modal](https://npm.io/package/@walletconnect/qrcode-modal.md) ^1.7.8
- [@walletconnect/web3-provider](https://npm.io/package/@walletconnect/web3-provider.md) 1.6.5

## Recent versions

- 1.0.12 (latest) — 2023-01-30
- 1.0.11 — 2023-01-24
- 1.0.10 — 2023-01-23
- 1.0.9 — 2023-01-21
- 1.0.8 — 2023-01-20
- 1.0.7 — 2023-01-20
- 1.0.6 — 2023-01-19
- 1.0.5 — 2022-12-06
- 1.0.4 — 2022-10-27
- 1.0.3 — 2022-09-27
- 1.0.2 — 2022-09-26
- 1.0.1 — 2022-07-26
- 1.0.0 — 2022-07-25
- 0.0.9 — 2022-07-18
- 0.0.8 — 2022-06-21
- … 8 more at https://npm.io/package/ng-blockchainx/versions

## README

# NgBlockchainX

Find Complete documentation here [Open docs ](https://blockchainxtech.github.io/ng-blockchain-x/docs/intro)

This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 12.2.0.

## Meta mask service

```typescript 

// 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 

```typescript 

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 

```typescript 
// '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
});

```



```typescript

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 code | Message | Description |
| :---: | :---: | :---: |
| 250511 | Metamask not installed on browser |  |
| 250512 | Metamask not connected |  |
| 250500 | Un expected error |  |
| 250601 | Metamask connected successfully |  |
| 250609 | Service init success | Just ignore this event |
| 250610 | Chain changed |  |
| 250611 | account changed |  |
| 250612 | metamask 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:

```bash
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

```typescript
{
    "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:

```typescript
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 

```js

{
    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

```typescript 

// 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) {}

```

---
_Source: https://npm.io/package/ng-blockchainx · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
