Heeellooo.
I’m Mr. Raccoon and today we’re gonna do something kinda fun. We’re gonna build a decentralized governance app on Lisk. :o
sounds like a trick? it kinda is. it’s called onchain voting. (power to the people tbh).
Note: There is a video version of this in case that we wanna take a look:
Youtube Link
so here’s the vibe:
First as base, we will clone the Scaffold Lisk repository.
git clone https://github.com/LiskHQ/scaffold-lisk.git
cd scaffold-lisk
code .
Once that we get inside the repo you can install your packages in the terminal like this:
cd packages/hardhat/
yarn
cd packages/nextjs/
yarn
In this tutorial we will use a public testnet instead of localhost, so we will need to get two ApiKeys:
Some other useful links that you may need are the Faucet and the Lisk network ready to be added to your wallet Lisk Sepolia Network
Okay, now that we’ve got our dev setup ready and some testnet juice, let’s move into the governance part. 🗳️
We’ll keep it super simple:
- Users will be able to create proposals (like “Change logo color to green”).
- Proposals will be stored on chain and everyone should be able to see it.
The smart contract looks like this:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
contract ProposalRegistry {
struct Proposal {
string title;
string description;
address proposer;
}
Proposal[] public proposals;
event ProposalCreated(
uint indexed id,
address indexed proposer,
string title
);
function createProposal(
string calldata title,
string calldata description
) external {
proposals.push(
Proposal({
title: title,
description: description,
proposer: msg.sender
})
);
emit ProposalCreated(proposals.length - 1, msg.sender, title);
}
function getAllProposals() external view returns (Proposal[] memory) {
return proposals;
}
function getProposalCount() external view returns (uint) {
return proposals.length;
}
}
you can copy it and paste in a new file in: packages/hardhat/contracts/ProposalRegistry.sol
then we will need a deploy script for this new contract that we created:
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
/**
* Deploys a contract named "ProposalRegistry" using the deployer account and
* constructor arguments set to the deployer address
*
* @param hre HardhatRuntimeEnvironment object.
*/
const deployProposalRegistry: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
/*
On localhost, the deployer account is the one that comes with Hardhat, which is already funded.
When deploying to live networks (e.g `yarn deploy --network sepolia`), the deployer account
should have sufficient balance to pay for the gas fees for contract creation.
You can generate a random account with `yarn generate` which will fill DEPLOYER_PRIVATE_KEY
with a random private key in the .env file (then used on hardhat.config.ts)
You can run the `yarn account` command to check your balance in every network.
*/
const { deployer } = await hre.getNamedAccounts();
const { deploy } = hre.deployments;
await deploy("ProposalRegistry", {
from: deployer,
// Contract constructor arguments
// args: [deployer], //Our conract doesnt have constructor
log: true,
// autoMine: can be passed to the deploy function to make the deployment process faster on local networks by
// automatically mining the contract deployment transaction. There is no effect on live networks.
autoMine: true,
});
};
export default deployProposalRegistry;
// Tags are useful if you have multiple deploy files and only want to run one of them.
// e.g. yarn deploy --tags ProposalRegistry
deployProposalRegistry.tags = ["ProposalRegistry"];
You must copy it in: packages/hardhat/deploy/deploy_proposal_registry.ts
And we are almost ready to deploy this on the lisk sepolia chain!
Once that we have the neccesary files, we need a DEPLOYER_PRIVATE_KEY to put in our envs, if it's your first time exporting it, here you have a nice tutorial.
with that set up, you can run:
npx hardhat deploy --network liskSepolia
You should see a message saying 4 smart contracts were deployed.
And that’s it! 🎉
Scaffold Lisk automatically detects contracts deployed by your address, so you don’t need to manually set an ABI or connect by address.
If you want to debug locally, just run:
yarn dev
and you should see this in the /debug path
If you want to verify your contract you can simply run:
npx hardhat verify --network liskSepolia YOUR_SMART_CONTRACT_ADDRESS
if the configuration is not set up, review your hardhat.config.ts file, and in the section of etherscan add:
etherscan: {
apiKey: {
liskSepolia: "abc",
},
customChains: [
{
network: "liskSepolia",
chainId: 4202,
urls: {
apiURL: "https://sepolia-blockscout.lisk.com/api",
browserURL: "https://sepolia-blockscout.lisk.com/",
},
},
],
},
(I took that configuration from this doc about how to verify in blockscout, you don't even need an api key)
and that's all! You got your contract on chain and you are ready to add new features or even modify this starter kit from here.
If you are looking for the github repo, here you have
and good luck building my fren!

Top comments (0)