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 / eth.effects.ts
Created April 12, 2018 12:19
The effects of the NGRX version of Angular and Ethereum
import { Injectable } from '@angular/core';
import { EthService } from './service';
// NGRX
import { Action } from '@ngrx/store';
import { Effect, Actions } from '@ngrx/effects';
import { EthError } from './../eth/actions';
import { GET_ACCOUNTS, GetAccountsSuccess } from './actions';
@GrandSchtroumpf
GrandSchtroumpf / eth.selectors.ts
Created April 12, 2018 12:21
The selectors for the NGRX version of Angular and Ethereum
import { EthState } from './eth.reducers';
export const getAccounts = (state: EthState) => state.eth.accounts;
export const getDefaultAccount = (state: EthState) => state.eth.selected;
@GrandSchtroumpf
GrandSchtroumpf / eth.module.ngrx.end.ts
Last active April 12, 2018 12:29
The final eth.module.ts file with reducers and effects
import { NgModule, ModuleWithProviders, Type } from '@angular/core';
import { CommonModule } from '@angular/common';
// Web3
import { WEB3 } from './tokens';
const Web3 = require('web3');
// SERVICES
import { AccountsService } from './eth.services';
// NGRX
import { StoreModule } from '@ngrx/store';
@GrandSchtroumpf
GrandSchtroumpf / eth.component.final.ts
Created April 12, 2018 12:33
The final eth.component.ts with NGRX selectors et store
import { Component, OnInit } from '@angular/core';
// NGRX
import { Store, select } from '@ngrx/store';
import { EthState, GetAccounts, getAccounts } from './ethereum';
// RXJS
import { Observable } from 'rxjs/Observable';
@Component({
@GrandSchtroumpf
GrandSchtroumpf / index.html
Created May 1, 2018 21:42
simple index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>DAPP</title>
</head>
<body>
<script src="web3.min.js"></script>
<script src="main.js"></script>
@GrandSchtroumpf
GrandSchtroumpf / simple-wallet.js
Last active May 6, 2018 17:28
Ethereum simple wallet
const web3 = new Web3('https://ropsten.infura.io/your-id');
// Create a account and store it encrypted in the localStorage
function createAndSaveAccount() {
const password = prompt('Mot de passe encrypter le compte');
const account = web3.eth.accounts.create();
const keystore = account.encrypt(password);
localStorage.setItem('keystore', JSON.stringify(keystore));
}
@GrandSchtroumpf
GrandSchtroumpf / hdwallet.js
Created May 13, 2018 19:29
A HDWallet for Ethereum
const bip39 = require('bip39');
const HDKey = require('hdkey');
const Web3 = require('web3');
const web3 = new Web3('https://ropsten.infura.io/your-id');
const mnemonic = bip39.generateMnemonic();
confirm(mnemonic);
const seed = bip39.mnemonicToSeed(mnemonic);
const masterNode = HDKey.fromMasterSeed(seed);
const derivationKey = "m/44'/60'/0'/0'/0";
@GrandSchtroumpf
GrandSchtroumpf / SendMessage-simple.sol
Created June 3, 2018 18:06
A simple version of the smart-contract SendMessage
pragma solidity ^0.4.23;
contract MessageSender {
mapping(address => string) public messages;
function sendMessage(address to, string content) public {
messages[to] = content;
}
}
@GrandSchtroumpf
GrandSchtroumpf / SendMessage.sol
Created June 3, 2018 20:05
Complete SendMessage Contract
pragma solidity ^0.4.23;
contract MessageSender {
struct Message {
address from;
string content;
}
mapping(address => Message) public messages;
@GrandSchtroumpf
GrandSchtroumpf / web3-service.ts
Created July 31, 2018 18:59
The classic way to import web3 in Angular
import { environment } from '../environments/environment';
import { bindNodeCallback, Observable } from 'rxjs';
@Injectable({ providedIn: 'root' })
export class Web3Service {
public web3: Web3;
constructor() {
this.web3 = new Web3(environment.web3Provider);