Write an Ethereum smart contract for a wallet with 5 joint account holders where 3 of 5 holders must authorize any send transaction

Write an Ethereum smart contract for a wallet with 5 joint account holders where 3 of 5 holders must authorize any send transaction:

  • carlos.sanchez
  • akpos.dleje
  • lorna.smith
  • janet.rios
  • mike.jones

Certainly! Here's an example of an Ethereum smart contract written in Solidity for a wallet with five joint account holders, where at least three out of the five holders must authorize any send transaction:

 

pragma solidity ^0.8.0;
 
contract MultiSigWallet { mapping(address => bool) public isAuthorized; uint public numAuthorized;
 
constructor(address[] memory initialAuthorized) { require(initialAuthorized.length == 5, "Initial authorized accounts must be 5"); for (uint i = 0; i < initialAuthorized.length; i++) { isAuthorized[initialAuthorized[i]] = true; } numAuthorized = 5; }
 
modifier onlyAuthorized() { require(isAuthorized[msg.sender], "Sender is not authorized"); _; } function authorizeAccount(address account) external onlyAuthorized { require(!isAuthorized[account], "Account is already authorized"); isAuthorized[account] = true; numAuthorized++; }
 
function revokeAuthorization(address account) external onlyAuthorized { require(isAuthorized[account], "Account is not authorized"); require(numAuthorized > 3, "Cannot revoke authorization, minimum 3 accounts required"); isAuthorized[account] = false; numAuthorized--; }
 
function send(address payable recipient, uint amount) external onlyAuthorized { require(address(this).balance >= amount, "Insufficient balance"); recipient.transfer(amount); } function getBalance() public view returns (uint) { return address(this).balance; } }

In this contract, the isAuthorized mapping keeps track of whether an account is authorized or not. The numAuthorized variable stores the count of currently authorized accounts. The onlyAuthorized modifier ensures that only authorized accounts can execute specific functions.

The constructor initializes the initial set of authorized accounts. The authorizeAccount function allows authorized accounts to add new authorized accounts. The revokeAuthorization function allows authorized accounts to revoke the authorization of other authorized accounts (with the condition that a minimum of three accounts remain authorized). The send function allows authorized accounts to send funds to a recipient, provided there are sufficient funds in the wallet. The getBalance function returns the balance of the wallet.

Please note that deploying and interacting with smart contracts require familiarity with tools like Remix IDE, Truffle, or the Ethereum command-line interface (CLI).

You should also read: