This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit, Inject } from '@angular/core'; | |
import { WEB3 } from './web3'; | |
import Web3 from 'web3'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.scss'] | |
}) | |
export class AppComponent implements OnInit { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { InjectionToken } from '@angular/core'; | |
import Web3 from 'web3'; | |
export const WEB3 = new InjectionToken<Web3>('web3', { | |
providedIn: 'root', | |
factory: () => new Web3(Web3.givenProvider) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BrowserModule } from '@angular/platform-browser'; | |
import { NgModule } from '@angular/core'; | |
import { ProviderModule } from '@ngeth/provider'; | |
import { AppComponent } from './app.component'; | |
@NgModule({ | |
declarations: [ | |
AppComponent | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import { Eth } from '@ngeth/provider'; | |
import { Observable } from 'rxjs'; | |
@Component({ | |
selector: 'app-root', | |
template: '<h1>Current Block : {{ block$ | async }}</h1>', | |
styles: [] | |
}) | |
export class AppComponent implements OnInit { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { InjectionToken } from '@angular/core'; | |
import { CommonModule } from '@angular/common'; | |
import Web3 from 'web3'; | |
// Create an Injection Token with web3 inside | |
export const WEB3 = new InjectionToken<Web3>('web3'); | |
@NgModule({ | |
imports: [ | |
CommonModule, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NgModule, ModuleWithProviders, InjectionToken} from '@angular/core'; | |
export const URL = new InjectionToken<string>('url'); | |
@NgModule({ | |
imports: [HttpClientModule] | |
}) | |
export class ProviderModule { | |
static init(url: string): ModuleWithProviders { | |
return { | |
ngModule: ProviderModule, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable, Inject } from '@angular/core'; | |
import { URL } from './provider.module'; | |
@Injectable({ providedIn: 'root' }) | |
export class Provider { | |
private rpcId: number; | |
constructor(@Inject(URL) private url: string) {} | |
/** JSON RPC Request */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { Provider } from 'provider.service.ts'; | |
import BN from 'bn'; | |
@Injectable({ providedIn : 'root' }) | |
export class Eth { | |
constructor(private provider: Provider) {} | |
/** Transform a value into hex or decimal string for example */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface ABIDefinition { | |
constant?: boolean; | |
payable?: boolean; | |
anonymous?: boolean; | |
inputs?: Array<ABIInput>; | |
name?: string; | |
outputs?: Array<ABIOutput>; | |
type: 'function' | 'constructor' | 'event' | 'fallback'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Type } from '@angular/core'; | |
import { ABIDefinition } from './models/abi.types'; | |
export function Contract(config: { | |
abi: ABIDefinition[], | |
address: string | |
}) { | |
return function(Target: Type<any>) { | |
class DecoratedContract extends Target { |