Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

François GrandSchtroumpf

🏠
Working from home
View GitHub Profile
@GrandSchtroumpf
GrandSchtroumpf / eth.effects.ts
Created Apr 12, 2018
The effects of the NGRX version of Angular and Ethereum
View eth.effects.ts
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 Apr 12, 2018
The selectors for the NGRX version of Angular and Ethereum
View eth.selectors.ts
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 Apr 12, 2018
The final eth.module.ts file with reducers and effects
View eth.module.ngrx.end.ts
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 Apr 12, 2018
The final eth.component.ts with NGRX selectors et store
View eth.component.final.ts
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({
View 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
Ethereum simple wallet
View simple-wallet.js
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
A HDWallet for Ethereum
View hdwallet.js
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 Jun 3, 2018
A simple version of the smart-contract SendMessage
View SendMessage-simple.sol
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 Jun 3, 2018
Complete SendMessage Contract
View SendMessage.sol
pragma solidity ^0.4.23;
contract MessageSender {
struct Message {
address from;
string content;
}
mapping(address => Message) public messages;
@GrandSchtroumpf
GrandSchtroumpf / web3-service.ts
Created Jul 31, 2018
The classic way to import web3 in Angular
View web3-service.ts
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);