1.0.0 • Published 1 year ago

@dsks/angular-web3-module v1.0.0

Weekly downloads
-
License
CC BY-SA
Repository
-
Last release
1 year ago

Angular Web3 Access Module

This library was generated with Angular CLI version 14.2.0.

How to use

Import module on app.module.ts

import { Web3ModuleModule } from '@dsks/angular-web3-module';

...

imports: [
  ...,
  Web3ModuleModule
],

Use it on html template

<lib-web3-module></lib-web3-module>

Import service on component

import { Web3ModuleService } from '@dsks/angular-web3-module';

Add it on the constructor

constructor(private web3ModuleService: Web3ModuleService)

Suscribe to service events

constructor(private web3ModuleService: Web3ModuleService) {
    // Suscribe to connect event
    this.web3ModuleService.getWeb3UserSubject().subscribe((user: any) => {
        console.log("User", user);
        if(user != null){
        // this.web3ModuleService.addSmartContract('test', '0x8a75B7F4237e56D126B64efCf1dAa88094033721', [{"inputs": [{"internalType": "uint256","name": "num","type": "uint256"}],"name": "store","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [],"name": "retrieve","outputs": [{"internalType": "uint256","name": "","type": "uint256"}],"stateMutability": "view","type": "function"}]);
        // let testSmartcontract = this.web3ModuleService.getSmartContract('test');
        // if(testSmartcontract != null && testSmartcontract.ethContract != null){
        //   testSmartcontract.ethContract.methods.retrieve().call().then((result: any) => {
        //     console.log("Result", result);
        //   });
        // }        
        }
    });

    // Suscribe to wallet events (ChainChanged & AccountsChanged)
    this.web3ModuleService.getWeb3EventSubject().subscribe((event: any) => {
        console.log("Event", event);
    });

    // Suscribe to errors (Wrong network, no wallet, etc.)
    this.web3ModuleService.getWeb3ErrorSubject().subscribe((error: any) => {
        console.log("Error", error);
    });
}

After View init set Network id, init module and forche change network

ngAfterViewInit() {
    // Init web3 module
    this.web3ModuleService.web3InitSubject.next([ new Network('137', 'Polygon Mainnet', 'MATIC', 'MATIC', 18, ['https://polygon-rpc.com/'], ["https://polygonscan.com/"]), 
                                                  new Network('80001', 'Polygon testnet (Mumbai)', 'MATIC', 'MATIC', 18, ['https://matic-mumbai.chainstacklabs.com/'], ['https://mumbai.polygonscan.com/'])]);
    this.web3ModuleService.forceChangeNetwork('80001');
}
1.0.0

1 year ago

0.9.3

1 year ago

0.8.0

1 year ago

0.9.2

1 year ago

0.9.1

1 year ago

0.7.0

1 year ago

0.6.0

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.0.1

1 year ago