React Hooks

Basic Hooks

useState

1
const [state, setState] = useState(initialState)

Read More

5 Tips in CRA@2.0

Origin

It’s fucking long time not learning React.

Read More

Assembly in Solidity

Inline Assembly

1
2


Read More

Analysis of Ujo

What is Ujo

The Ujo platform uses blockchain technology to create a transparent and decentralized database of rights and rights owners, automating royalty payments using smart contracts and cryptocurrency.

Read More

Development of Neuron Web Extension

Create Project

1
create-react-app neuron-web scripts-version=react-scripts-ts

Read More

Details in Web3 -- Contract

Basic Usage

1
2
3
4
5
// To initialize a contract

var Contract = require('web3-eth-contract')
Contract.setProvider('ws://localhost:8546')
var contract = new Contract(abi, address, options)

Read More

Declaration in TypeScript

Read More

RxjsV6

animationFrame - scheduler

1
const animationFrame: any;

Read More

Content Parser in CITA

The parse now we used is

1
2
3
4
5
6
7
8
9
10
11
const parser = (content: string) => {
const bytes = hexToBytes(content)
const decoded = pb.UnverifiedTransaction.deserializeBinary(bytes)
const tx = decoded.getTransaction()
return {
from: tx.getFrom ? tx.getFrom() : '',
to: tx.getTo ? tx.getTo() : '',
data: tx.getData ? tx.getData() : '',
value: tx.getValue ? tx.getValue().toString() : ''
}
}

Read More

GenServer in Erlang

Original

GenServer is essential part of OTP, which simplifies repeating tasks, letting programmer concentrate on logic of the application, and not on handling edge cases and repeated error handling.

Read More

Association in Phoenix

Original

Associations

Associations in Ecto are used when two difference sources(tables) are linked via foreign keys.

Read More

Difference Bwtween Build_assoc, Put_assoc, and Cast_assoc

Cast Assoc code

Read More

Introduction to Object.getOwnPropertyDescriptors

Object.getOwnPropertyDescriptors

This method returns all properties including getter and setter.

Read More

Enable Sass/scss in Phoenix

Step 1: Add brunch

1
cd assets && yarn add sass-brunch

Read More

Model Generator of Rails

Origin

Basic Usage

1
rails g model User email

Read More

Error Handling in Solidity

Solidity uses state-reverting exceptions to handle errors. Such an exception will undo all changes made to the state in the current call(and all its sub-calls) and also flag an error to the caller. The convenience function assert and require can be used to check for conditions and throw an exception if the condition is not met.

Read More

Start in Drizzle

Drizzle is a collection of front-end libraries that make wirting dapp front-ends easier and more predicable. The core of Drizzle is based on Redux Store, so you can access to the spectacular development tools around Redux. We take care of synchronizing your contract data, transaction data and more. Things stay fast because you declare what to keep in sync.

Read More

Constant, View, and Pure in Solidity

Summary

  • pure for functions: Disallows modifition or access of state - this is not enforeced yet.

Read More

Writing Upgradable Contracts in Solidity

origin

Ethereum contracts are immutable – once deployed to the blockchain they cannot be updated, yet the need to change their logic with time is ultimately necessary.

Read More

Dockerizing a React App

origin

Project Setup

Install create-react-app

Read More

Deploy RoR With Mina

Mina Setup

Let’s take a look at setting up Mina with Puma. First, you’ll need to add Mina and mina-puma in Gemfile.

Read More

What Blockchain Came With

MindMap

Read More

Ethereum + IPFS

MindMap

Read More

Gas Used by Public and External Function in Solidity

Origin

Read More

智能合约编写注意事项

原文连接

Read More

Start in Protobuf

Protocol Buffers are a language-neutral, platform-neutral, extensible way of serializing structured data for use in commnucations protocols, data storage, and more, originally designed at Google.

Read More

Get the Most Out of the CommonsChunkPlugin

Origin

Read More

Go Web

Origin

Introduction

Go is a battery included programming language and has a webserver already built
in.

Read More

Generate Ethereum Keys and Wallet Address

Origin

This article is a guide on how to generate an ECDSA private key and derives
its Ethereum address.

Read More

Caution on Int8Array

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
let t = crypto.getRandomValues(new Int8Array(3))
// Int8Array(3) [-15, -17, -90]

// t is not typeof Array
Array.isArray(t)
// false

// element in Int8Array must be type Int8
// method map returns array of same type as origin array
let _t = []
t.map(i => {
let _tmp = i.toString(16)
_t.push(_tmp)
return _tmp
})
// Int8Array(3) [0, -11, 0]
// _t: ['-f', '-11', '-5a']

t[0] = 'a'
// t: Int8Array(3) [0, -17, -90]

Read More

Client Wallet Inspection

Read More

React-Lodable

react-lodable is a higher order component for loading components with dynamic
imports.

Code-splitting is the process of taking one large bundle containing your entire
app, and splitting them up into multiple smaller bundles which contain seperate
parts of your app.

Read More

Difference Between Contract Calling in Web3

After we get the instance of Contract(testInstance), we can invoke its method by three ways:

  • testInstance.testFunc.sendTransaction()

Read More

JSON-PRC

Read More

Common Patterns in Contract

Withdrawal from Contract

The recommended method of sending funds after an effect is using the withdrawal pattern.

Read More

Solidity Style Guide

Layout

4 spaces per indentation level

Use spaces for indentation

Read More

Notes on Solidity in Depth

Layout of a Solidity Source File

Version Pragma

1
pragma solidity ^0.4.11;

Read More

Solidity CheatSheet

Global Variables

Block

    Read More

    HTTP/2 by Node.js

    Origin

    Websites delivered using HTTP/2 enjoys a wide range of new features including -

    Read More

    Rocket of Rust

    Introduction

    Rocket’s design is centered around three core philosophies:

    Read More

    Fastify Plugin Guide

    In Fastify everything is a plugin, your routes, your utilities and so on are all plugins. And to add a new plugin, whatever its functionality is, in Fastify

    Read More

    Time to Start Fastify

    Getting Started

    Install

    1
    yarn add fastify

    Read More

    Apollo With TypeScript

    Origin

    Start with a simple React Component wrapped with the graphql higher order component from React Apollo.

    Read More

    Source Code of Koa-Static

    Source Code

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    'use strict'

    /**
    * Module Dependencies
    */

    const debug = require('debug')('koa-static')
    const { resolve } = require('path')
    const assert = require('assert')
    const send = require('koa-send')

    /**
    * Expose `serve()`
    */

    module.exports = serve

    /**
    * Serve static files from `root`
    *
    * @param {String} root
    * @param {Object} [opts]
    * @return {Function}
    * @api public
    */

    function serve (root, opts) {
    opts = opts || {}

    // ensure `root`
    assert(root, 'root directory is required to serve files')

    // options
    debug('static %s %j', root, opts)
    // set opts.root to absolute one
    opts.root = resolve(root)

    // set default static file
    if (opts.index !== false) opts.index = opts.index || 'index.html'

    // if defer is supported
    if (!opts.defer) {
    return async function serve (ctx, next) {
    let done = false

    if (ctx.method === 'HEAD' || ctx.method === 'GET') {
    try {
    done = await send(ctx, ctx.path, opts)
    } catch (err) {
    if (err.status !== 404) {
    throw err
    }
    }
    }

    if (!done) {
    await next()
    }
    }
    }

    retrun async function serve (ctx, next) {
    await next()
    if(ctx.method !== 'HEAD' && ctx.method !== 'GET') return
    // response is already handled
    if (ctx.body != null || ctx.status !== 404) return

    try {
    await send(ctx, ctx.path, opts)
    } catch (err) {
    if (err.status !== 404) {
    throw err
    }
    }
    }
    }

    Read More

    React-Hot-Loader in Webpack With Ts-Loader

    It’s very easy to integrate react-hot-loader into webpack with ts-loader.

    Config the webpack

    Add Hot Module Replacement

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    // webpack.entry
    app: [
    'webpack/hot/only-dev-server',
    'webpack-dev-server/client?http://localhost:8080',
    path.resolve(__dirname, './src'),
    ],

    plugins: [
    new webpack.HotModuleReplacementPlugin()
    ],

    devServer: {
    hot: true,
    }

    Read More

    Methods of Observable

    Origin
    Playground

    Read More

    HTTP Timings in Node.js

    Origin

    Some Basic Concepts:

      Read More

      Graphql-Koa-Starter

      Init Project

      Add tsconfig

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      // tsconfig.json
      {
      "files": [
      "server.ts"
      ],
      "compilerOptions": {
      "outDir": "./build",
      "target": "es2015",
      "module": "commonjs",
      "moduleResolution": "Node",
      "sourceMap": true,
      "pretty": true,
      "strictNullChecks": true,
      "lib": [
      "esnext"
      ]
      },
      "exclude": [
      "node_modules",
      "build"
      ]
      }

      Read More

      Tag Picture in Html

      The picture element is a markup pattern that allows developers to declare multiple sources for an image.

      This markup is a container used to specify multiple <source> elements for a specific <img> contained in it.

      Read More

      Simple Example of DAPP

      Use truffle to init Project

      Contract of Adoption

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      // contracts/Adoption.sol
      pragma solidity ^0.4.4;


      constract Adoption {
      address[16] public adopters;

      function adopt (uint petId) public returns (uint) {
      require(petId >= 0 && petId <= 15);
      adopters[petId] = msg.sender;
      return petId;
      }

      function getAdopters () public returns (addresss[16]) {
      return adopters;
      }
      }

      Read More