Recently, I’ve developed an interesting business using multi-sign wallet.
This project, requires tokens(ERC20) can be only minted by someone who approved by multiple administrators. I decided to implement those multi-approvals by administrators using multi-sign wallet.
-
First of all, there must be or we’re implementing a contarct for
CRUDing to minters.contract AddressPrivileges { ... function addMinter(address _addMinter) public validCall returns (bool) {...} function delMinter(address _delMinter) public validCall returns (bool) {...} function isMinter(address account) public view returns (bool) {...} modifier onlyMinter() {...} ... } -
Here is multiSignature.sol
contract multiSignature { ... function createApplication(address to) external returns(uint256) { bytes32 msghash = getApplicationHash(msg.sender, to); uint256 index = signatureMap[msghash].length; signatureMap[msghash].push(signatureInfo(msg.sender, new address[](0))); emit CreateApplication(msg.sender, to, msghash); return index; } function signApplication(bytes32 msghash) external onlyOwner validIndex(msghash, defaultIndex) { emit SignApplication(msg.sender, msghash, defaultIndex); signatureMap[msghash][defaultIndex].signatures.addWhiteListAddress(msg.sender); } ... }When user clicks a button like
add minterfrom FE, it callsmultiSignature.sol:createApplicationfunction first :createApplication(${address of AddressPrivileges contract})to hashes the ${address ofAddressPrivileges} and users address , put the hash into a signatureMap.Then administrators can see these pending approvals in their end.
Once they all approved the request from their site, FE calls
signApplicationto add their address to the signatureMap.signatureInfo.signatures. (signatures[] is empty beforesignApplicationfunction, it was a signatureMap[msghash] [empty] ) -
After approved by multi-sign wallets , now it’s fine to call
addMinterinAddressPrivileges.sol, bcz we can’t pass thevalidCallcheck til multi-sign approval.modifier validCall() { checkMultiSignature(); _; }
I would not say too much to breakdown those source codes wrote in my style , it’s not important , for now the matter is to get the mind.
Cool.