Merit Money Swapper is a project that explores the possibilities of Hedera smart contracts and contract interaction using Vue framework.
This project is built on the Hedera blockchain platform and is written in Solidity, JavaScript, and Vue.
hashgraph/sdk
hardhat
nomiclabs/hardhat-ethers
openzeppelin/contracts
vue
To install the project, run:
npm install
To compile the contracts run:
npx hardhat compile
The contract artifacts should be located in the project root under artifacts
directory.
Loading Swapper
abi:
import { abi } from '../artifacts/contracts/Swapper.sol/Swapper.json';
-
Create
Deployer
account here. ECDSA. -
Add deployer keys to .env file.
-
Create
Admin
account using hashpack wallet and fund withUSDC
usingDeployer
. -
Create
Employee
account using hashpack wallet and fund withBT
usingDeployer
. -
Create both tokens on
testnet
withDeployer
account.
Barrage token:
npm run create-barrage-token
output:
🚀 Created Barrage FT, BARRAGE_TOKEN_ID: 0.0.15073453
USDC token:
npm run create-usdc-token
output:
🚀 Created USDC FT, USDC_TOKEN_ID: 0.0.15073479
Add tokenIds to .env file.
Find contract addresses for both tokens here and add to .env file.
- Associate both
Admin
&Employee
account with new tokens using hashpack wallet.
For the association you'll need to login into hashpask wallet for admin
and employee
and associate those accounts with new tokens.
- Transfer BT to
Employee
& USDC toAdmin
npm run transfer-bt
npm run transfer-usdc
In this scripts you can adjust amounts, sender & receiver based on your needs for testing.
- Contract deployment
Setup the contract deployer in hardhat.config.js
.
const PRIVATE_KEY = process.env.TREASURY_HEX_PRIVATE_KEY;
Script for deploy
uses hardhat
for contract deployment.
The complied contracts should be deployed with the command:
npm run deploy-contract
Script output:
Swapper contract address: 0x81c2e51a55f21b0246754C4e11C749F0f2C8d443
The recommendation is to off-load the deployment to backend service. The reason is that you can't deploy such large contract with hashpack wallet.
Because of that suggestion is to read privKey
from vault
or .env
file and then deploy the contract using backend service.
Look up for tokenId
from deployed Swapper
here and add to .env file.
You've should also add tokenId
to HashConnectStore
.
Has to be done using backend service as deployer must grant role to the ADMIN.
As the PRIVATE_KEY defined in hardhat.config.js
is the contract ADMIN
that account must grant role
to merit-money COMPANY_ADMIN which will be responsible for whitelisting EMPLOYEES
to the Swapper
, contract management, depositing etc.
The EMPLOYEES
must be whitelisted so that have a right to Swap
their bonus tokens with stablecoin.
Run command:
npm run grant-admin-role
From now on, everything can be approved by hashpack wallet.
This will approve SC to transfer usdc tokens.
This will approve SC to transfer barrage tokens.