This artefact is built as part of my thesis on central bank digital currencies (CBDCs). The artefact is a decentralized app (dApp) built using:
- Hardhat (Ethereum development environment)
v2.20.1
- OpenZeppelin (smart contracts)
v5.0.1
- Ethers.js (web3 library)
v6.11.1
- React.js (frontend library)
v18.2.0
- User deposits fiat currency
- Central bank generates a digital signature.
- Equivalent CBDC tokens are minted in central bank's wallet.
- User enters signature and smart contracts verifies it.
- Tokens are transferred in user's wallet.
MetaMask wallet is used to confirm transactions and sign messgages.
- We have utilized EIP-20 as our token standard. Our CBDC tokens exist as ERC20 tokens.
- We have utlized EIP-712 as our signature signing standard.
- We have used EIP-2612 as our signature approval standard.
git clone https://github.com/faranak-cs/cbdc.git
- Open
cbdc
folder in VS Code and enter the following command in VS Code CLI to install Hardhat dependencies:
npm install
Use the same command to install React dependencies but first change directory to cbdc/frontend
by using following command:
cd frontend
Now install dependencies.
npm install
Go back to parent directory cbdc
using cd ..
- Compile the smart contracts by using the following command in VS Code CLI:
npx hardhat compile
- Write the following command in a new VS Code CLI instance. This will spin up a local Ethereum blockchain.
npx hardhat node
Keep that CLI instance running.
- Now deploy the smart contracts on local Ethereum blockchain using the following command:
npx hardhat run .\scripts\deploy.js --network localhost
- We need MetaMask wallet to be configured with our local Ethereum blockchain. Open MetaMask. Go to
Setting > Networks > Add a network > Add a network manually
. Now enter the following details and hitSave
.
- Network Name:
Hardhat-localhost
- New RPC URL:
http://127.0.0.1:8545/
- Chain ID:
31337
- Currency symbol:
ETH
- We need two Chrome browser profiles. One is for central bank's perspective and other one for users' perspective.
- Now add three Ethereum accounts that were generated in step 5. Do this on both Chrome profiles. Open MetaMask. Go to
Select an account > Add account > Import account
. For Simplicity, enter the following details to add accounts and hitImport
.
- Enter your private key string here:
0xdf57089febbacf7ba0bc227dafbffa9fc08a93fdc68e1e42411a14efcf23656e
Name this account as CB
(Central bank).
0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
Name this account as P1
(Person 1)
0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a
Name this account as P2
(Person 2)
10. All installations and configurations are done.
- Local Ethereum blockchain should be running and smart contracts should be deployed.
- Change the directory to
cbdc/frontend
. Now Enter the following command:
npm run dev
- Application should start running on
http://localhost:5173/
- Copy the url and paste it on other Chrome profile.
- Application should be running on both Chrome profiles.
- Go to Chrome profile (central bank) and connect MetaMask.
- Go to Deposit page. Enter amount and wallet address and hit
Deposit
. - MetaMask
Signature Request
will pop up. Sign it. - After successful transaction, a 65-bytes signature will be appeared. Copy it.
- Go to Chrome profile (user) and connect MetaMask.
- Go to Mint page and paste the signature.
- Enter the same wallet address and amount and hit
Mint
. - MetaMask transactions will pop up. Confirm them.
- After successful transactions, tokens will be minted.
- Copy the same wallet address.
- Go to Home page. Paste the address and hit
Check
. - Available tokens will be displayed.
Demo.final.mp4
Source: https://cbdctracker.org/