Skip to content

Instantly share code, notes, and snippets.

View GrandSchtroumpf's full-sized avatar
🏠
Working from home

François GrandSchtroumpf

🏠
Working from home
  • Dapps Nation
  • Nantes
View GitHub Profile
@GrandSchtroumpf
GrandSchtroumpf / simple-appcomponent-web3.ts
Created July 31, 2018 19:21
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 {
@GrandSchtroumpf
GrandSchtroumpf / angular6-web3-token.ts
Created July 31, 2018 19:29
The way to create a web3 token with
import { InjectionToken } from '@angular/core';
import Web3 from 'web3';
export const WEB3 = new InjectionToken<Web3>('web3', {
providedIn: 'root',
factory: () => new Web3(Web3.givenProvider)
});
@GrandSchtroumpf
GrandSchtroumpf / app.module.ts
Created August 23, 2018 17:18
@ngeth : add ProviderModule
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ProviderModule } from '@ngeth/provider';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
@GrandSchtroumpf
GrandSchtroumpf / app.component.ts
Created August 23, 2018 18:17
@ngeth in your component
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 {
@GrandSchtroumpf
GrandSchtroumpf / minimum-ethModule.ts
Last active August 31, 2018 12:02
The old way to build an Ethereum module that exposes the WEB3 Token
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,
@GrandSchtroumpf
GrandSchtroumpf / provider.module.ts
Last active September 2, 2018 12:57
A module to provide the URI of an Ethereum node
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,
@GrandSchtroumpf
GrandSchtroumpf / provider.service.ts
Created September 2, 2018 13:15
The provider service to manage RPC calls
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 */
@GrandSchtroumpf
GrandSchtroumpf / eth.service.ts
Created September 2, 2018 13:45
Handles JSON-RPC methods for Ethereum
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 */
@GrandSchtroumpf
GrandSchtroumpf / abi.types.ts
Created September 3, 2018 07:19
Types for the ABI
export interface ABIDefinition {
constant?: boolean;
payable?: boolean;
anonymous?: boolean;
inputs?: Array<ABIInput>;
name?: string;
outputs?: Array<ABIOutput>;
type: 'function' | 'constructor' | 'event' | 'fallback';
}
@GrandSchtroumpf
GrandSchtroumpf / contract.ts
Created September 3, 2018 07:28
The contract Decorator (empty)
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 {