Deploying a Multisignature Wallet Smart Contract on Ethereum

Posted By : Amit

Nov 30, 2019

In this blog, we will be deploying a multi-signature wallet contract on a local Ethereum private network setup.

 

We are setting up the MultiSigWallet contract made open source by the gnosis project and it can be accessed here.

 

After compiling the source code on the Remix tool, we get the wallet contract's ABI details and deploy on our private network, passing in the required signature values to initiate a transaction as 2 and the following addresses as the initial owners - ["0x38ce8c9e1843ebb88edb952551963fda0d0fa0ba", "0x3f817bc1e7c52c341a6de942850f23f88fc476d6"].

 

On the private network, the contract is deployed at the address 0x7b6c5e7f9f7d2a81e400fb176ca95f781f6005e4, using this address, we load the contract instance, hereby referred as myinstance.

 

To confirm the above details, we call the getOwners() method on the contract -

 

mwinstance.getOwners(), which results in the following address [] output - ["0x38ce8c9e1843ebb88edb952551963fda0d0fa0ba", "0x3f817bc1e7c52c341a6de942850f23f88fc476d6"]. You can check the required confirmations for executing the transaction through - mwinstance.requirements () which returns 2.

 

Adding Ether Balance to the Multisig wallet

 

Now, the first thing needed to be done is to transfer some ethers to the contract's address, the contract accepts ether as it has a payable function of the form

 

    function()
    payable public
    {
        if (msg.value > 0)
           emit Deposit(msg.sender, msg.value);
    }

 

and emits a Deposit event, when it receives some ETH.

 

event Deposit(address indexed sender, uint value);

 

To check the contract's ether balance, we can use the eth.getBalance method itself.

 

Transfer ETH from the contract to some address 

 

a) Let one of the owners submit a transaction using the method

 

    function submitTransaction(address destination, uint value, bytes data)
    public
    returns (uint transactionId)
    {
        transactionId = addTransaction(destination, value, data);
        confirmTransaction(transactionId);
    }

 

submitTransaction function then calls the addTransaction method

 

    function addTransaction(address destination, uint value, bytes data)
    internal
    notNull(destination)
    returns (uint transactionId)
    {
        transactionId = transactionCount;
        transactions[transactionId] = Transaction({
            destination: destination,
            value: value,
            data: data,
            executed: false
            });
        transactionCount += 1;
        emit Submission(transactionId);
    }

 

This function updates the transaction mapping stored in the contract and also the transactionCount on the smart contract.

 

On the console, use the following call to initiate a transfer of Ether from the contract -

 

mwinstance.submitTransaction(eth.accounts[198],web3.toWei(0.1,"ether"),"0x",{from:"0x38ce8c9e1843ebb88edb952551963fda0d0fa0ba",gas:900000})

 

This initiates the submission of a transaction, and the transaction gets one approval as it is sent by one of the owners.

 

b) Approving the transaction by the other owner

 

    function confirmTransaction(uint transactionId)
    public
    ownerExists(msg.sender)
    transactionExists(transactionId)
    notConfirmed(transactionId, msg.sender)
    {
        confirmations[transactionId][msg.sender] = true;
        emit Confirmation(msg.sender, transactionId);
        executeTransaction(transactionId);
    }

 

To fetch the transaction ID you want to confirm, get it as follows

 

mwinstance.transactions(6), in the above example the transaction id is 6, the result of this call is
["0x832652e6ca3393daf3f9318ffc3b5199e85fa440", 100000000000000000, "0x", false]

 

'false' indicates that the transaction has not been executed.

 

To execute it, the other owner makes a call like


mwinstance.confirmTransaction(6,{from:"0x3f817bc1e7c52c341a6de942850f23f88fc476d6",gas:900000})

 

Once both calls are successful, you can see via transaction receipts as logs emitted by those transactions. You can also check the latest balances of the accounts and the contract address.

 

For more information about Ethereum or wallet smart contract development, connect with our crypto wallet development experts

Leave a

Comment

Name is required

Invalid Name

Comment is required

Recaptcha is required.

blog-detail

November 21, 2024 at 12:01 pm

Your comment is awaiting moderation.

By using this site, you allow our use of cookies. For more information on the cookies we use and how to delete or block them, please read our cookie notice.

Chat with Us
Telegram Button
Youtube Button

Contact Us

Oodles | Blockchain Development Company

Name is required

Please enter a valid Name

Please enter a valid Phone Number

Please remove URL from text