Skip to content

Instantly share code, notes, and snippets.

@GrandSchtroumpf
Created July 31, 2018 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GrandSchtroumpf/c59f9f67665a852763f60a97190318ce to your computer and use it in GitHub Desktop.
Save GrandSchtroumpf/c59f9f67665a852763f60a97190318ce to your computer and use it in GitHub Desktop.
A simple appcomponent that print the network on which you are connected
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 {
constructor(@Inject(WEB3) private web3: Web3) {}
ngOnInit() {
this.web3.eth.net.getId()
.then(id => console.log(`You are connected on ${this.getNet(id)}`));
}
private getNet(id: number): string {
const networks = {
1: 'mainnet',
3: 'ropsten',
4: 'rinkeby',
42: 'koven'
};
return networks[id];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment