1.1.0 • Published 5 years ago
@rsksmart/ethr-did-utils v1.1.0
npm i ganache-core @rsksmart/ethr-did-utilsFeatures
- Start a Ganache HTTP server and deploy Ethr DID Registry
Usage
You can start a Ganache server and deploy the registry from a new terminal or from Node.js
From a new terminal
Open a new terminal browse to the repo dir or clone it and run
npm run start-ganache-and-deployThe output should be
Ganache started on port 8545 - rpcUrl: http://localhost:8545
Ethr DID Registry depoyed - registryAddress: 0xe87c1cd63e5eed53db7d4e839adb7a4646ecbf8d
netowrks: [ { name: 'ganache', rpcUrl: http://localhost:8545, registryAddress: 0xe87c1cd63e5eed53db7d4e839adb7a4646ecbf8d }]
mnemonic: cover lift maple eagle common differ trash stomach scene security section dismissUseful for demos
From Node.js
To start the server and deploy from Node.js
const { startGanacheServerAndDeployEthrDidRegistry } = require('@rsksmart/ethr-did-utils')
const port = process.env.PORT || 8545
startGanacheServerAndDeployEthrDidRegistry(port).then(({ blockchain, server, rpcUrl, eth, registryAddress, registry }) => {
console.log(`Ganache started on port ${port} - rpcUrl: ${rpcUrl}`)
console.log(`Ethr DID Registry depoyed - registryAddress: ${registryAddress}`)
console.log(`netowrks: [ { name: 'ganache', rpcUrl: ${rpcUrl}, registryAddress: ${registryAddress} }]`)
console.log(`mnemonic: ${blockchain.mnemonic}`)
eth.accounts() // use ethjs
.then(([me]) => registry.identityOwner(me)) // use ethr did registry contract
.then(result => result[0])
.then(owner => console.log(`My identity owner is ${owner}`))
.then(() => server.close()) // use server.close to exit ganache
})This sample script is in demo.js and can be run with node demo.js
The output should be
Ganache started on port 8545 - rpcUrl: http://localhost:8545
Ethr DID Registry depoyed - registryAddress: 0x351e99cafac04bd08333b06f1f8257ec5abfe242
netowrks: [ { name: 'ganache', rpcUrl: http://localhost:8545, registryAddress: 0x351e99cafac04bd08333b06f1f8257ec5abfe242 }]
mnemonic: host spin zero toddler chat tortoise project buffalo example ship chair human
My identity owner is 0xf9bcb26dbd250b22162ee513e9c6f9f373ced425Useful for testing
API
async function startGanacheServerAndDeployEthrDidRegistry(port)Start a Ganache server and deploy Ethr DID Registry
Parameters:
portport to for the server to listen on - default8545
Returns: Promise<Object> with keys of startGanacheServer and deployEthrDidRegistry,
serverblockchainethrpcUrlregistryregistryAddress
async function startGanacheServer(port)Parameters:
portport to for the server to listen on - default8545
Returns: Promise<Object> with keys
serverthe Ganache server started. It has a functioncloseto close the server connectionblockchainthe success result of the server listen callbackethanethjsinstance using via HTTP the started serverrpcUrlthe URL to use to connect to the node via RPC
async function deployEthrDidRegistry(eth)Start a Ganache server and deploy Ethr DID Registry
It works only with auto-miner set on
Parameters:
ethanethjsinstance using via HTTP the started server
Returns:
registryanethjs-contractinstance of the deployed registryregistryAddressthe address of the deployed Ethr DID Registry