**Problem Faced:
**Single-owner wallets are prone to security risks, such as hacks or losing a private key.
Solution:
A multisig wallet (multi-signature) requires multiple owners to approve transactions before execution.
solidity
pragma solidity ^0.8.0;
contract MultiSigWallet {
address[] public owners;
uint public required;
struct Transaction {
address to;
uint value;
bool executed;
uint approvalCount;
}
mapping(uint => mapping(address => bool)) public approvals;
Transaction[] public transactions;
constructor(address[] memory _owners, uint _required) {
owners = _owners;
required = _required;
}
function submitTransaction(address _to, uint _value) external {
transactions.push(Transaction({ to: _to, value: _value, executed: false, approvalCount: 0 }));
}
function approveTransaction(uint _txIndex) external {
Transaction storage txn = transactions[_txIndex];
require(!approvals[_txIndex][msg.sender], "Already approved");
approvals[_txIndex][msg.sender] = true;
txn.approvalCount++;
if (txn.approvalCount >= required) {
txn.executed = true;
payable(txn.to).transfer(txn.value);
}
}
}
Build secure, scalable, and customized blockchain solutions tailored to your business needs. From smart contract development to decentralized applications, get end-to-end services for your blockchain projects. Our blockchain development ensures seamless integration, high security, and innovative solutions for Web3, DeFi, and enterprise blockchain applications. Let’s shape the future of decentralized technology together!
Top comments (0)