Srs 4 Srs 5 Srs 6
Multi-Signature Account
A fictional case study
A year ago, Raymond walked into a bank subsequent to a discussion he had with his girlfriend. They concluded to have a joint account and a separate account for daily spending. They are two different human and sexes with different mindsets and ways of thinking. Even though they loved each other yet, instincts reminded them of the dynamic nature of man. One of them could grow naughty overnight or become wild suddenly, hence the decision to abandon sentiments to approach a bank for a joint account as they planned towards the future.
On Algorand, several real-life issues have their paired solutions. MultiSig wallet would have been their best solution if awareness had reached them.
Experimenting real-life use case with Algorand solution
Last month, Raymond met Bob who is a smart contract developer on Algorand. He told him his past ordeal and currently experiencing same with his fiancee. Bob introduced him to Algorand solution. Now he is happy to want to implement this solution with his fiancee. They have agreed to create a multisig account with the following rules:
- An account for savings.
- Either of them can transfer fund to the savings account without fear that the other party will spend or withdraw without notifying the other.
- None of them should be able to spend on trivialities.
- They want a spending account
- Two parties as signatures for approving withdrawal or any form of transfer.
Back in our code editor, I have created another file named multiSig.py
. Multisig account have some resemblances with creating an individual account but its uniqueness is in 100% obedience to the predefined set of rules. We are going to integrate every line of instructions based on our client's demand.
wifeAddress
, store her privateKey as wifePrivateKey
. Notice we use a prefix wife
right? Cool. This is because we are wishing them a happy married life in advance. In actual coding, you don't want to have the knowledge of her private keys. You only need to write the instructions in a way that will ask her as input.- Next we we call our already established
connectToNetwork()
function fromconnect.py
file. - Get suggested parameters.
- Call
generateAccounts()
function which launches 3 new accounts fromgenerateaccount
module, stores the result inaccounts
dictionary. Line16
does this jobs and we only print the result to the console from17
. req
is number of signatories to the Multisig wallet.21
is required by inbuiltMultisig
class that initiatesmultisig
function.- From the 3 accounts we created from
16
, we assigned first account as Raymond's account address and its private key in23
.
- In line
27
, we registered both parties' addresses as the required number of signatories. - They will be able to withdraw from
savingsAccount
tospendAccount
only if both parties signatures are collected from37
and38
, enjoined in36
and broadcast in39
where the connection is available. - When multisig transaction is initiated, a wallet is generate automatically by the network and its private key does not exist. Therefore, none of the parties can lobby for the key since it can be used to move funds away from the account. Isn't that cool? In
29
, we are only printing the multisig account information, also, address which we represent as the savings account as the instruction says in33
. 35
specifies the structure of fund withdrawal fromsavingAlcAddr
(multisig account) tospendAccount
with the amount to withdraw waiting to be signed
How To Create Transaction Group.
Aside of creating individual account and multisig accounts, there are cases where working with transaction groups can be very useful and helpful. This model is often implemented in exchanges.
pythonTutorial.py
file. I created a file - pythonMain_day7.py
to execute it.What changed!.
- Moved transaction parameters to a function
create_transaction
in a new filecreateTransaction.py
In
sendtransaction.py
file, created three different transactions from three accounts generated fromcreate_transaction()
we imported - lines12
to14
, grouped them together -17
to19
.16
, the grouping is done using a list of transaction IDs generated from hash of calculating the trio.21
to23
signs each of transactions with paired private keys.Then we broadcast the group to the network enclosed as array of objects in a list.