@ngeth/eth
v0.0.5
Published
> The `eth` module of web3 rebuild for Angular
Downloads
12
Readme
@ngeth/eth
The
eth
module of web3 rebuild for Angular
Setup
npm install @ngeth/eth --save
Import EthModule
import { AppComponent } from './app.component';
import { EthModule } from '@ngeth/eth';
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
EthModule.forRoot(/* Provider */), // You can add a custom Provider here
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
EthService
The EthService
map the web3-eth
methods into Observable
.
import { Component, OnInit } from '@angular/core';
import { EthService } from '@ngeth/eth';
import { Observable } from 'rxjs';
@Component({
selector: 'app-root',
template: `
<p>Current Block: {{ block$ | async }}</p>
<ul>
<li *ngFor="let account of accounts$ | async">
{{ account }}
</li>
</ul>
`,
styles: []
})
export class AppComponent implements OnInit {
public assets$: Observable<number>;
public accounts$: Observable<string>;
constructor(private eth: EthService) {}
ngOnInit() {
this.block$ = this.eth.getBlockNumber();
this.accounts$ = this.eth.getAccounts();
}
}
Contracts
The main strength of @ngeth/eth
is the way it instanciate contract :