npm package: @peopledata/registry-contract
Description: Basic contract for registering DID / DID Document mappings
Author: jerry zhang
Latest version: 1.2.0

# RegistryContract

The repository contains the source code for the Ethereum smart contract used as part of our did:peopledata method spec implementation. The project also includes a configured truffle environment for compiling, testing and deploying the contract, and a wrapper class allowing for easier integration.

This is a lower level module used by the peopledata-did-registry (integration) and peopledata-did-resolver (integration) packages to offer a more consumable API.


## Complie contarcts
Before using `truffle compile` , one should config the compile by create `truffle-config.js`.  
```bash
$ truffle compile 
```

If everthing is ok, a `build` directory should be generated by compiler and the output of above command should be
like this:
```bash

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
⠹ Fetching solc version list from solc-bin. Attempt #1

Starting migrations...
======================
> Network name:    'development'
> Network id:      12
> Block gas limit: 30000000 (0x1c9c380)


1_initial_migration.js
======================
⠸ Fetching solc version list from solc-bin. Attempt #1
   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0x9d444d5f703466692f16ef140e2461540496b27a73707b1318db268e913e109f
   > Blocks: 0            Seconds: 0
   > contract address:    0xEae831aB1a304869053b6B5D928d49D2A3718FD4
   > block number:        1
   > block timestamp:     1660691527
   > account:             0x408fd912F1bd3298293dbFF23F37d52a13f37aB4
   > balance:             999.99919035775
   > gas used:            239894 (0x3a916)
   > gas price:           3.375 gwei
   > value sent:          0 ETH
   > total cost:          0.00080964225 ETH

   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:       0.00080964225 ETH

Summary
=======
> Total deployments:   1
> Final cost:          0.00080964225 ETH
```





## Make Tests
* When use `npm run test`, don't start ganache local network.


## Useing Ropsten testnet

1. Transfer fund from Metamask account to local wallet address. The defaule address is the first account that ganache generated.

2. Command
```bash
$ npm run deploy:testnet 
```
The output should be like this:

```bash
npm run deploy:testnet

> @peopledata/registry-contract@1.0.1 deploy:testnet
> truffle deploy --network ropsten


Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
⠙ Fetching solc version list from solc-bin. Attempt #1
⠧ Fetching solc version list from solc-bin. Attempt #1
Migrations dry-run (simulation)
===============================
> Network name:    'ropsten-fork'
> Network id:      3
> Block gas limit: 30000000 (0x1c9c380)


1_initial_migration.js
======================
⠴ Fetching solc version list from solc-bin. Attempt #1
   Deploying 'Migrations'
   ----------------------
   > block number:        12805038solc-bin. Attempt #1
   > block timestamp:     1660709759
   > account:             0xeb463588eBDA1a340AfB1Af43Ca41DBA2d7809D0
   > balance:             1.999400264998320742
   > gas used:            239894 (0x3a916)
   > gas price:           2.500000007 gwei
   > value sent:          0 ETH
   > total cost:          0.000599735001679258 ETH

   -------------------------------------in. Attempt #1
   > Total cost:     0.000599735001679258 ETH


2_deploy_contracts.js
=====================
⠹ Fetching solc version list from solc-bin. Attempt #1
   Deploying 'Registry'
   --------------------
   > block number:        12805040
   > block timestamp:     1660709763
   > account:             0xeb463588eBDA1a340AfB1Af43Ca41DBA2d7809D0
   > balance:             1.998336539995342312
   > gas used:            379742 (0x5cb5e)
   > gas price:           2.500000007 gwei
   > value sent:          0 ETH
   > total cost:          0.000949355002658194 ETH

Deployed at:  0x7034E3955d46ed4EEE038373482bc7A551c6042E
   -------------------------------------in. Attempt #1
   > Total cost:     0.000949355002658194 ETH

Summary
=======
> Total deployments:   2
> Final cost:          0.001549090004337452 ETH


⠏ Fetching solc version list from solc-bin. Attempt #1
⠴ Fetching solc version list from solc-bin. Attempt #1
Starting migrations...
======================
> Network name:    'ropsten'
> Network id:      3
> Block gas limit: 30000000 (0x1c9c380)


1_initial_migration.js
======================
⠙ Fetching solc version list from solc-bin. Attempt #1
   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0x4c687703acfef6f62717f5bfdf443c9fdbee095c7f9735b13bb0c0eea46e1f4c
   > Blocks: 1            Seconds: 13c-bin. Attempt #1
   > contract address:    0xD5938785672c7CE4d0EE2C1995A02275deB6a68C
   > block number:        12805045
   > block timestamp:     1660709784
   > account:             0xeb463588eBDA1a340AfB1Af43Ca41DBA2d7809D0
   > balance:             1.999400264998320742
   > gas used:            239894 (0x3a916)
   > gas price:           2.500000007 gwei
   > value sent:          0 ETH
   > total cost:          0.000599735001679258 ETH

   > Saving migration to chain.om solc-bin. Attempt #1
   > Saving artifacts to chain.
   -------------------------------------
   > Total cost:     0.000599735001679258 ETH

⠹ Fetching solc version list from solc-bin. Attempt #1
2_deploy_contracts.js
=====================
⠸ Fetching solc version list from solc-bin. Attempt #1
   Deploying 'Registry'
   --------------------
   > transaction hash:    0xe9e034869ac82d8fe562838b3c09c59d73ecc72efc221b614aa3b4e2cd0ce2b8
   > Blocks: 1            Seconds: 17c-bin. Attempt #1
   > contract address:    0x7034E3955d46ed4EEE038373482bc7A551c6042E
   > block number:        12805049
   > block timestamp:     1660709832
   > account:             0xeb463588eBDA1a340AfB1Af43Ca41DBA2d7809D0
   > balance:             1.998336539995342312
   > gas used:            379742 (0x5cb5e)
   > gas price:           2.500000007 gwei
   > value sent:          0 ETH
   > total cost:          0.000949355002658194 ETH

Deployed at:  0x7034E3955d46ed4EEE038373482bc7A551c6042E
   > Saving migration to chain.om solc-bin. Attempt #1
   > Saving artifacts to chain.
   -------------------------------------
   > Total cost:     0.000949355002658194 ETH

Summary
=======
> Total deployments:   2
> Final cost:          0.001549090004337452 ETH
```

3. Check the transaction on etherscan.io
 we use [ropsten.etherscan.io](http://ropsten.etherscan.io)

 Find the contract address from above output: `0xD5938785672c7CE4d0EE2C1995A02275deB6a68C` of Migration contract and `0x7034E3955d46ed4EEE038373482bc7A551c6042E` of the Registry contarct.


> NOTICE: Change to Goerli Testnet aftet Aug 20, 2022.

Deploy on Goerli Testnet should be like this: 

```bash
> @peopledata/registry-contract@1.0.2 deploy:testnet
> truffle deploy --network goerli


Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
⠴ Fetching solc version list from solc-bin. Attempt #1
⠴ Fetching solc version list from solc-bin. Attempt #1
Migrations dry-run (simulation)
===============================
> Network name:    'goerli-fork'
> Network id:      5
> Block gas limit: 30000000 (0x1c9c380)


1_initial_migration.js
======================
⠼ Fetching solc version list from solc-bin. Attempt #1
   Deploying 'Migrations'
   ----------------------
   > block number:        7456586 solc-bin. Attempt #1
   > block timestamp:     1661242904
   > account:             0xE36A283B378a73e999CCCcc4Dd7d444783d8a5d4
   > balance:             0.099364677387447334
   > gas used:            239894 (0x3a916)
   > gas price:           2.648347239 gwei
   > value sent:          0 ETH
   > total cost:          0.000635322612552666 ETH

   -------------------------------------in. Attempt #1
   > Total cost:     0.000635322612552666 ETH


2_deploy_contracts.js
=====================
⠴ Fetching solc version list from solc-bin. Attempt #1
   Deploying 'Registry'
   --------------------
   > block number:        7456588 solc-bin. Attempt #1
   > block timestamp:     1661242908
   > account:             0xE36A283B378a73e999CCCcc4Dd7d444783d8a5d4
   > balance:             0.098251752707540956
   > gas used:            379742 (0x5cb5e)
   > gas price:           2.613887447 gwei
   > value sent:          0 ETH
   > total cost:          0.000992602846898674 ETH

Deployed at:  0x172BAb3DdD152a6066783E329Aafbe931cEFfF83
   -------------------------------------in. Attempt #1
   > Total cost:     0.000992602846898674 ETH

Summary
=======
> Total deployments:   2
> Final cost:          0.00162792545945134 ETH


⠇ Fetching solc version list from solc-bin. Attempt #1
⠙ Fetching solc version list from solc-bin. Attempt #1
Starting migrations...
======================
> Network name:    'goerli'
> Network id:      5
> Block gas limit: 30000000 (0x1c9c380)


1_initial_migration.js
======================
⠹ Fetching solc version list from solc-bin. Attempt #1
   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0xfc9189f9acc7d7480d91078334c366a228aff3d39613728c67ca6ff98af1c374
   > Blocks: 2            Seconds: 17c-bin. Attempt #1
   > contract address:    0x0A93bd23f7afFa91ee32b4D15F5a9B5a297DFAca
   > block number:        7456593
   > block timestamp:     1661242932
   > account:             0xE36A283B378a73e999CCCcc4Dd7d444783d8a5d4
   > balance:             0.099364057861912016
   > gas used:            239894 (0x3a916)
   > gas price:           2.650929736 gwei
   > value sent:          0 ETH
   > total cost:          0.000635942138087984 ETH

   > Saving migration to chain.om solc-bin. Attempt #1
   > Saving artifacts to chain.
   -------------------------------------
   > Total cost:     0.000635942138087984 ETH

⠼ Fetching solc version list from solc-bin. Attempt #1
2_deploy_contracts.js
=====================
⠇ Fetching solc version list from solc-bin. Attempt #1
   Deploying 'Registry'
   --------------------
   > transaction hash:    0x3578c9b770ff8abd9118e7518cd41a06a0d9a6943eab4e0d8eee6907d7d2f56f
   > Blocks: 2            Seconds: 17c-bin. Attempt #1
   > contract address:    0x172BAb3DdD152a6066783E329Aafbe931cEFfF83
   > block number:        7456597
   > block timestamp:     1661242992
   > account:             0xE36A283B378a73e999CCCcc4Dd7d444783d8a5d4
   > balance:             0.098235979216059456
   > gas used:            379742 (0x5cb5e)
   > gas price:           2.652484122 gwei
   > value sent:          0 ETH
   > total cost:          0.001007259625456524 ETH

Deployed at:  0x172BAb3DdD152a6066783E329Aafbe931cEFfF83
   > Saving migration to chain.om solc-bin. Attempt #1
   > Saving artifacts to chain.
   -------------------------------------
   > Total cost:     0.001007259625456524 ETH

Summary
=======
> Total deployments:   2
> Final cost:          0.001643201763544508 ETH
```