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'; |
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; |
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'; |
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> |
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)); | |
} |
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"; |
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; | |
} | |
} |
View SendMessage.sol
pragma solidity ^0.4.23; | |
contract MessageSender { | |
struct Message { | |
address from; | |
string content; | |
} | |
mapping(address => Message) public messages; |
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); |