Posted By : Amit
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 -
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.
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 -
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
'false' indicates that the transaction has not been executed.
To execute it, the other owner makes a call like
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.
November 18, 2024 at 11:59 pm
Your comment is awaiting moderation.