Skip to content

This smart contract program defines a multi-signature wallet that requires multiple signatures to access the funds. It can be used as a secure way to manage assets that require more than one person's approval for transactions.

License

Notifications You must be signed in to change notification settings

nasserhaji/MultiSigWallet

Repository files navigation

Smart Contract for a Multi-Signature Wallet & Token Wallet

Overview

This smart contract program defines a multi-signature wallet that requires multiple signatures to access the funds. It can be used as a secure way to manage assets that require more than one person's approval for transactions.

This smart contract program defines a multi-signature wallet that requires multiple signatures to access the funds. It can be used as a secure way to manage assets that require more than one person's approval for transactions.

This smart contract is designed to create a wallet for storing ERC20 tokens. It allows users to add new tokens to their wallet, view their token balances, and transfer tokens to other addresses.

This smart contract was written in Solidity, a programming language for smart contracts on the Ethereum blockchain. It utilizes the OpenZeppelin library for ERC20 token functionality.

Implementation

The smart contract is written in Solidity, a programming language used for developing smart contracts on the Ethereum blockchain. It defines a contract called MultiSigWallet that has the following functions:

  • constructor(uint _required, address[] memory _owners) initializes the contract with the required number of signatures (_required) and the addresses of the wallet owners (_owners).
  • fallback() and receive() functions that allow the contract to receive funds.
  • deposit() allows anyone to deposit funds into the wallet.
  • submitTransaction(address payable _to, uint _value, bytes memory _data) creates a new transaction with the specified parameters and returns the transaction ID.
  • confirmTransaction(uint _transactionId) confirms a pending transaction.
  • revokeConfirmation(uint _transactionId) revokes a previous confirmation for a transaction.
  • executeTransaction(uint _transactionId) executes a confirmed transaction if it has received enough confirmations.

Usage

To use this multi-signature wallet, follow these steps:

  1. Deploy the smart contract on the Ethereum blockchain with the required number of signatures (_required) and the addresses of the wallet owners (_owners).
  2. Deposit funds into the wallet using the deposit() function.
  3. Create a new transaction using the submitTransaction() function with the recipient address (_to), the amount of ether to send (_value), and the data to include with the transaction (_data).
  4. Wait for the required number of wallet owners to confirm the transaction using the confirmTransaction() function.
  5. Execute the transaction using the executeTransaction() function.
  6. Deploy the Smart Wallet contract on the Ethereum network using Remix or Truffle.
  7. Deploy the Token contract on the Ethereum network using Remix or Truffle.
  8. Connect the Token contract to the Smart Wallet contract by calling the addTokenContract function in the Smart Wallet contract. This allows the Smart Wallet to hold and manage the tokens from the Token contract.
  9. Use the sendFunds function in the Smart Wallet contract to send ether from the Smart Wallet to a recipient address.
  10. Use the transferToken function in the Smart Wallet contract to transfer tokens from the Smart Wallet to a recipient address.
  11. Use the withdrawToken function in the Smart Wallet contract to withdraw tokens from the Smart Wallet to an external address.
  12. Use the getBalance function in the Token contract to check the balance of tokens in the Smart Wallet.
  13. Use the approve function in the Token contract to approve the Smart Wallet to spend tokens on behalf of the owner.
  14. Use the transferFrom function in the Token contract to allow the Smart Wallet to transfer tokens on behalf of the owner.
  15. To use the Smart Wallet and Token contracts in a DApp, follow the steps below: a. Import the Smart Wallet and Token contract ABIs into your DApp. b. Initialize the Smart Wallet and Token contract instances in your DApp. c. Use the Smart Wallet and Token contract instances to interact with the contracts as needed in your DApp.

Functions

  • addTokenContract(address _tokenContractAddress, string memory _tokenName) Adds a new ERC20 token contract to the wallet. Requires the user to input the address of the token contract and a name for the token.

  • removeTokenContract(address _tokenContractAddress) Removes an existing ERC20 token contract from the wallet. Requires the user to input the address of the token contract to be removed.

  • getTokenBalance(address _tokenContractAddress, address _userAddress) view returns (uint256) Returns the token balance of the specified user's address for the specified token contract address.

  • transferTokens(address _tokenContractAddress, address _recipientAddress, uint256 _amount) Transfers the specified amount of tokens from the sender's address to the recipient's address. Requires the user to input the address of the token contract, the recipient's address, and the amount of tokens to be transferred.

  • approveTokens(address _tokenContractAddress, address _spenderAddress, uint256 _amount) Allows the specified spender's address to transfer the specified amount of tokens from the sender's address. Requires the user to input the address of the token contract, the spender's address, and the amount of tokens to be approved.

  • transferFrom(address _tokenContractAddress, address _senderAddress, address _recipientAddress, uint256 _amount) Transfers the specified amount of tokens from the sender's address to the recipient's address on behalf of the approved spender. Requires the user to input the address of the token contract, the sender's address, the recipient's address, and the amount of tokens to be transferred.

  • getContractOwner() view returns (address) Returns the address of the owner of the token wallet contract.

  • isContract(address _address) view returns (bool) Checks if the input address is a contract address.

Events

  • TokenContractAdded(address _tokenContractAddress, string _tokenName) Emitted when a new ERC20 token contract is added to the wallet. Provides the address of the added token contract and its name.

  • TokenContractRemoved(address _tokenContractAddress) Emitted when an existing ERC20 token contract is removed from the wallet. Provides the address of the removed token contract.

  • TokensTransferred(address _tokenContractAddress, address _senderAddress, address _recipientAddress, uint256 _amount) Emitted when tokens are transferred from one address to another. Provides the address of the token contract, the sender's address, the recipient's address, and the amount of tokens transferred.

  • TokensApproved(address _tokenContractAddress, address _spenderAddress, uint256 _amount) Emitted when tokens are approved for transfer by a spender's address. Provides the address of the token contract, the spender's address, and the amount of tokens approved.

Benefits

This smart contract program provides several benefits:

  • It offers a secure way to manage assets that require multiple approvals for transactions.
  • It is decentralized, meaning that there is no need for a trusted third party to manage the wallet.
  • It provides transparency and immutability by recording all transactions and confirmations on the Ethereum blockchain.
  • It is programmable, meaning that it can execute transactions automatically without the need for manual intervention.

The last benefit is particularly useful in cases where multiple transactions need to be executed automatically. For example, a business could use this smart contract to manage payroll for its employees. The contract could be programmed to execute salary payments on a specific day each month, without the need for manual intervention from the business owners. This reduces the risk of errors and improves efficiency.

Conclusion

In conclusion, the Smart Wallet and Token contracts presented in this document provide a secure and efficient way to manage ether and tokens on the Ethereum network. By deploying and using these contracts, users can enjoy the benefits of a decentralized financial system that is transparent, secure, and accessible to all. We hope that this document has provided you with the necessary information to get started with using the Smart Wallet and Token contracts in your own Ethereum-based applications.

Overall, this smart contract program provides a powerful tool for managing assets securely and programmatically on the Ethereum blockchain.

About

This smart contract program defines a multi-signature wallet that requires multiple signatures to access the funds. It can be used as a secure way to manage assets that require more than one person's approval for transactions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published