@rsksmart/ethr-did-utils
v1.1.0
Published
Utils for Ethr DID method in RSK network
Downloads
6
Readme
npm i ganache-core @rsksmart/ethr-did-utils
Features
- 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-deploy
The 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 dismiss
Useful 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 0xf9bcb26dbd250b22162ee513e9c6f9f373ced425
Useful for testing
API
async function startGanacheServerAndDeployEthrDidRegistry(port)
Start a Ganache server and deploy Ethr DID Registry
Parameters:
port
port to for the server to listen on - default8545
Returns: Promise<Object>
with keys of startGanacheServer
and deployEthrDidRegistry
,
server
blockchain
eth
rpcUrl
registry
registryAddress
async function startGanacheServer(port)
Parameters:
port
port to for the server to listen on - default8545
Returns: Promise<Object>
with keys
server
the Ganache server started. It has a functionclose
to close the server connectionblockchain
the success result of the server listen callbacketh
anethjs
instance using via HTTP the started serverrpcUrl
the 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:
eth
anethjs
instance using via HTTP the started server
Returns:
registry
anethjs-contract
instance of the deployed registryregistryAddress
the address of the deployed Ethr DID Registry