Quick-start
When running the proof of concept, there are three features that need to be run simultaneously: the blockchain node, the real-world service provider, and the consumer.
Hardhat node
Clone the sep-contracts
repository:
git clone https://github.com/rndlabs/sep-contracts
Install the dependencies:
cd sep-contracts
yarn
Compile typechain
artifacts:
yarn hardhat compile
Generate a mnemonic
that you can use for test accounts. To do so, you can use this BIP39 generator. At the Mnemonic Code Converter:
- Select ‘24’ words from the drop-down box.
- Press ‘GENERATE’
- Copy the results of the
BIP39 Mnemonic
field to clipboard for the next step.
Configure the environment variables (.env
), within the cloned repository’s root directory to be similar to:
# network specific node uri : `"ETH_NODE_URI_" + networkName.toUpperCase()`
ETH_NODE_URI_MAINNET=https://eth-mainnet.alchemyapi.io/v2/<apiKey>
ETH_NODE_URI_SOKOL=https://sokol.poa.network
ETH_NODE_URI_GNOSIS=https://rpc.xdaichain.com
# generic node uri (if no specific found) :
ETH_NODE_URI=https://{{networkName}}.infura.io/v3/<apiKey>
# network specific mnemonic : `"MNEMONIC_ " + networkName.toUpperCase()`
# MNEMONIC_MAINNET=<mnemonic for mainnet>
# generic mnemonic (if no specific found):
MNEMONIC=<paste your mnemonic here with greater than/less than symbols>
# forking
# HARDHAT_FORK=gnosis
# coinmarketcap api key for gas report
COINMARKETCAP_API_KEY=
REPORT_GAS=true
# Etherscan API key for automatic verification of contracts
ETHERSCAN_API_KEY=
Now start the hardhat local blockchain for testing:
yarn hardhat node
When starting the hardhat local node, search through the console output for the address at which the ServiceProvider
contract was deployed. Example:
deploying "ServiceProvider" (tx: 0x717c1eb6649abe7b92a0a2bead9b9f3b505da385980486283e5912ac90d699a9)...: deployed at 0x29b67856f9ca63dF5E688454B17F70Afd5071aa0 with 1758370 gas
In the above example, the ServiceProvider
contract was deployed to 0x29b67856f9ca63dF5E688454B17F70Afd5071aa0
. Copy the address where it deployed on your local hardhat node as this will be used in subsequent configuration. For now though, your local blockchain node is running and ready to accept connections!
Server
Open another terminal window and clone the sep
repository.
Be sure not to clone
sep
into thesep-contracts
directory.
git clone https://github.com/rndlabs/sep
Install the dependencies:
yarn # installs lerna for monorepo
yarn lerna bootstrap # bootstrap packages
Change to the demo
directory:
cd packages/demo
Generate the protobuf TypeScript:
yarn protoc --ts_out ./src/proto --proto_path ./src/proto ./src/proto/*
Copy over the typechain
artifacts from the sep-contracts
repo:
cp -pR path/to/sep-contracts/typechain .
Configure the environment varibles (.env
) in the demo
directory to be similar to:
MNEMONIC=<paste your mnemonic from before here with greater than/less than symbols>
SERVER_KEY_INDEX=1
CLIENT_KEY_INDEX=2
RPC_URL=http://127.0.0.1:8545
SEP_DAPP_NAME=sep-movi
SEP_DAPP_VERSION=1
REGISTRY_ADDRESS=<fill in with deployment address from sep-contracts>
SELLER_NAME=Testing Seller
SELLER_DATA_URI=http://testurl/
SELLER_LOCATION=u173z
Now, you can start the server
, and this will simulate being a service provider:
yarn ts-node ./src/server.ts
At this point, you should see the following activity:
- The
server
registers a testseller
. - The
server
registers 5space
s for thesellerHash
from (1). - The
server
connects toWaku
to monitor applicablecontent-topic
s.
This activity will be visible on the node as well as on the server
.
Client
Open another terminal window and change into the demo
package’s directory:
cd path/to/demo
All the configuration for the client
has already been done from the previous steps, so we can now run the client
to make a query for a ride:
yarn ts-node ./src/client.ts
At this point, you should see the following activity:
- The
client
connects toWaku
and asks (ping) for allsellerHash
in a certain shard. - The
server
responds (pong)with it’ssellerHash
and some additional details. - The
client
verifies the pong from theserver
against theServiceProvider
contract. - The
client
, knowing there is a legitimateseller
, asks for a stay with specific parameters (check-in, check-out, number of adults, number of children, number of spaces). - The
server
receives the query from (4) and dispatches this to anauctioneer
that takes theask
parameters as input. It’s then determined if theseller
wants to make abid
for this business. - The
server
crafts a signed bid toclient
. - The
client
verifies theserver
’s bid, and chooses one of the offers. - The
client
uses the bid’ssignature
to make the deal on-chain. - The
server
, through event monitoring, can see that theclient
has made the deal. 🥳
Sometimes there are connectivity issues to
Waku
from theclient
. UseCtrl + C
to terminate theclient
and start it again.