contract MultisigTutorial {
address[] public owners;
mapping(address => bool) public isOwner;
uint public numConfirmationsRequired;
}
owners
: An array containing the addresses of all owners of the multi-signature wallet.isOwner
: A mapping indicating whether an address is an owner.numConfirmationsRequired
: The number of confirmations required for a transaction.modifier
special keyword to amend the behavior of functions
mapping(address => bool) public isOwner;
modifier onlyOwner() {
require(isOwner[msg.sender], "not owner");
_;
}
onlyOwner
modifier ensures that only owners can execute a function. It does this by checking whether the address of the caller is an owner.
constructor
defines a function that executed only once during the deployment of the contract.
uint public numConfirmationsRequired;
constructor(address[] memory _owners, uint _numConfirmationsRequired) {
require(_owners.length > 0, "owners required");
require(
_numConfirmationsRequired > 0 &&
_numConfirmationsRequired <= _owners.length,
"invalid number of required confirmations"
);
for (uint i = 0; i < _owners.length; i++) {
address owner = _owners[i];
require(owner != address(0), "invalid owner");
require(!isOwner[owner], "owner not unique");
isOwner[owner] = true;
owners.push(owner);
}
numConfirmationsRequired = _numConfirmationsRequired;
}
It initializes essential parameters, in this case, the list of owners and the required number of confirmations. (temporarily assign to isOwner
for assure uniqueness)
Functions can be declared view
in which case they promise not to modify the state.
pragma
import
event
error
interface
library
contract
event
error
modifier
function
constructor
receive
function (if exists)fallback
function (if exists)external
public
internal
private
function (<parameter types>) {internal | external} [pure | view | payable] [returns (<return types>)]