This repository uses Hardhat tasks as a simple for of a CLI for interacting with contract deployments on local and public networks. Tasks are defined in javascript files in this subdirectory and grouped based on their concerns. In order to register a new task with Hardhat, the file the task is written in must be imported into the hardhat.config.js at the root of this package.
Look at available tasks defined by the CLI:
npx hardhat --help
First, start a Hardhat development node to host the contract stack on a local blockchain: You need to specify the port to bypass a hardhat quirk.
npx hardhat node --port 8569
Leave this process running and start a new terminal/console. In the new console, deploy the contract stack: network 'dev' is configured to listen to 8569
npx hardhat run scripts/deployment.js --network dev
/*
Deploying MinimalForwarder contract...
MinimalForwarder deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
MinimalForwarder Gas Fee: 658010
Deploying Consent implementation contract...
Consent deployed to: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
Consent Gas Fee: 3401692
Deploying Consent Factory contract...
ConsentFactory deployed to: 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
ConsentFactory Gas Fee: 3296490
Deploying Doodle Token contract...
DoodleToken deployed to: 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9
DoodleToken Gas Fee: 1769284
Deploying Timelock Controller contract...
SnickerdoodleTimeLock deployed to: 0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9
SnickerdoodleTimeLock Gas Fee: 2186574
Deploying SnickerdoodleGovernor (DAO) contract...
SnickerdoodleGovernor deployed to: 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707
SnickerdoodleGovernor Gas Fee: 3973069
Deploying Crumbs contract...
Crumbs deployed to: 0x0165878A594ca255338adfa4d48449f69242Eb8F
Crumbs Gas Fee: 2510537
Deploying Sift contract...
Sift deployed to: 0xa513E6E4b8f2a923D98304ec87F64353C4D5C853
Sift Gas Fee: 2503414
----TX Mined---
Blocknumber: 53
TX Hash: 0x56939d8f105c31a756949915fce83d1e895c04722cd0e141ab7cc963c4d54464
Gas Used: 162656
----TX Mined---
Blocknumber: 54
TX Hash: 0x6e1ef5b1434c576413dfd9ff979ac936afc1f8880e5603271dd1fa5d4031b0c7
Gas Used: 110851
Full deployment successful!
*/
Next, you make a request to the factory to create a consent contract. Provide the address to set as the owner of the deployed Consent contract.
npx hardhat createConsentContract --owneraddress 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 --baseuri www.uri.com --name MYCONSENT --accountnumber 1 --network dev
/*
Concent Contracts owned by this account: [ '0xE451980132E65465d0a498c53f0b5227326Dd73F' ]
*/
You can check confirm the deployed consent contract by running a check against the factory. It takes the owner's address a lists down the
npx hardhat checkConsentContractByRole --owneraddress 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 --network dev
/*
DEFAULT_ADMIN_ROLE Membership: [ '0xE451980132E65465d0a498c53f0b5227326Dd73F' ]
PAUSER_ROLE Membership: [ '0xE451980132E65465d0a498c53f0b5227326Dd73F' ]
SIGNER_ROLE Membership: [ '0xE451980132E65465d0a498c53f0b5227326Dd73F' ]
REQUESTER_ROLE Membership: [ '0xE451980132E65465d0a498c53f0b5227326Dd73F' ]
*/
You can now submit a few requestForData transaction in order to generate a few
RequestForData events that can be picked up by an event listener subscribed to
the contract. Provide the target consent address, the CID, and account number. If the transaction was succesfully mined, the even has been emitted on chain.
npx hardhat requestForData --network dev --consentaddress 0xE451980132E65465d0a498c53f0b5227326Dd73F --accountnumber 1 --cid QmdsB4FMQ2jBfrTL2kx6Eaq5Up8rF44h6aqPP9BPpHDAq9
Finally, retrieve a list of the requested data through the events emitted by passing in the arguments for the target consent address and the owner's address.
npx hardhat listRequestedDataByOwner --consentaddress 0xE451980132E65465d0a498c53f0b5227326Dd73F --owneraddress 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 --network dev
/*
Query Horizon Block is: 118 (this value will vary from your local run)
Queried address: 0xE451980132E65465d0a498c53f0b5227326Dd73F
Request number: 1
Owner address: 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
Requested CID: QmdsB4FMQ2jBfrTL2kx6Eaq5Up8rF44h6aqPP9BPpHDAq9
*/
When an address that does not have the required role on the Consent contract's function tries to execute it, the transaction will revert. In the example below, account number 2, does not have the REQUESTER_ROLE to request for data. Trying to make a request for data will fail.
npx hardhat requestForData --network dev --consentaddress 0xE451980132E65465d0a498c53f0b5227326Dd73F --accountnumber 2 --cid QmdsB4FMQ2jBfrTL2kx6Eaq5Up8rF44h6aqPP9BPpHDAq8
/*
An unexpected error occurred:
...
AccessControl: account 0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc is missing role 0x61a3517f153a09154844ed8be639dabc6e78dc22315c2d9a91f7eddf9398c002 //bytes32 of 'REQUESTER_ROLE'
*/
To solve this, we can grant roles to specific addresses to allow access to certain functions on the Consent contract. The example below grants accounts 2 (0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc) the REQUESTER_ROLE.
npx hardhat grantRole --consentaddress 0xE451980132E65465d0a498c53f0b5227326Dd73F --accountnumber 1 --grantee 0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc --role REQUESTER_ROLE --network dev
Now it would be able to request for data as it was a function only executed by an address with the REQUESTER_ROLE. 0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc in this example is the address of index 2 in Hardhat's default addresses.
npx hardhat requestForData --network dev --consentaddress 0xE451980132E65465d0a498c53f0b5227326Dd73F --accountnumber 2 --cid QmdsB4FMQ2jBfrTL2kx6Eaq5Up8rF44h6aqPP9BPpHDAq8
Similarly, we can also revoke the role as below.
npx hardhat revokeRole --consentaddress 0xE451980132E65465d0a498c53f0b5227326Dd73F --accountnumber 1 --revokee 0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc --role REQUESTER_ROLE --network dev
Now when an address has been revoked the REQUESTER_ROLE tries to request for data, the transaction reverts with the following error.
npx hardhat requestForData --network dev --consentaddress 0xE451980132E65465d0a498c53f0b5227326Dd73F --accountnumber 2 --cid QmdsB4FMQ2jBfrTL2kx6Eaq5Up8rF44h6aqPP9BPpHDAq8
/*
An unexpected error occurred:
...
AccessControl: account 0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc is missing role 0x61a3517f153a09154844ed8be639dabc6e78dc22315c2d9a91f7eddf9398c002 //bytes32 of 'REQUESTER_ROLE'
*/
We can create crumbs:
npx hardhat createCrumb --crumbid 1 --tokenuri 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --accountnumber 0 --network dev
And burn crumbs:
npx hardhat burnCrumb --crumbid 1 --accountnumber 0 --network dev
We can verify urls on the Sift contract by running:
npx hardhat verifyURL --url www.domain.com --owner 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --accountnumber 0 --network dev
We can also mark urls on the Sift contract as malicious by running:
npx hardhat maliciousURL --url www.baddomain.com --owner 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --accountnumber 0 --network dev
To check any url's status on the contract, run the following:
npx hardhat checkURL --url www.domain.com --network dev
/*
Checked! URL www.domain.com is www.sift.com/VERIFIED.
*/
npx hardhat checkURL --url www.baddomain.com --network dev
*/
Checked! URL www.baddomain.com is www.sift.com/MALICIOUS.
*/
npx hardhat checkURL --url www.new.com --network dev
*/
Checked! URL www.new.com is NOT VERIFIED.
*/