Deploying a Multisignature Wallet Smart Contract on Ethereum

Deploying a Multisignature Wallet Smart Contract on Ethereum

Posted By : Amit Kumar | 30-Nov-2019

In this blog, we will be deploying a multisignature 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 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 net, the contract is deployed at the address 0x7b6c5e7f9f7d2a81e400fb176ca95f781f6005e4, using this address, we load the contract instance, hereby referred as mwinstance.

 

To confirm the above details, we call the getOwners() method on the contract as -
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 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 the calls are succesful, you can see via transactionreceipts the logs emitted by those transactions. You can also check the latest balances of the accounts and contract address.

About Author

Amit Kumar

Amit is a Backend Developer and previously created web apps using javascript, HTML, CSS, Jquery . His hobbies are playing football and listening music.

Leave a Comment

Name is required

Comment is required

Leave a Comment

    Request For Proposal

    Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.

    We would love to hear from you!

    Oodles | Blockchain Development Company

    Please enter a valid Phone Number

    Please remove URL from text

    Recaptcha is required.