create account

GSWPUA-Day-7: Multisig account concept with example and use case, how to create a transaction group and likely error with description by bob-elr

View this thread on: hive.blogpeakd.comecency.com
· @bob-elr · (edited)
$0.05
GSWPUA-Day-7: Multisig account concept with example and use case, how to create a transaction group and likely error with description
<div class="pull-left">
https://images.hive.blog/DQmPT8qfqANVCaXCoKwt3oTLekNgo2wEatsCnkWVSai5Pyv/image.png
Before now, following previous tutorial, we have established connection(using REST APIs), generate</div><div class="pull-right"> accounts(private key, address and/or public key conversion), transfer token between accounts and query the network for account information. Let's try some new stuffs.</div>

[src](https://www.google.com/search?q=day+7&sxsrf=ALeKk00UikfAmn-bc-yjBJISP1qAJtM73A:1590866122338&tbm=isch&source=iu&ictx=1&fir=sC2IrzNVwJPKRM%253A%252CCwCqWHdcd6GgpM%252C_&vet=1&usg=AI4_-kRUM-jXis2qgPfzFGSjeTgcaJUCKg&sa=X&ved=2ahUKEwiKoO2QptzpAhUJkRQKHcv7C8EQ9QEwAXoECAEQKg#imgrc=sC2IrzNVwJPKRM:)

****

<center>==>Previously on<==</center>
<center>**[Srs 1](https://hive.blog/python/@bob-elr/python-become-a-programmer-and-build-real-world-traditional-or-decentralized-applications-on-platforms-such-algorand-blockchain)**  **[Srs 2](https://hive.blog/python/@bob-elr/build-on-algorand-blockchain-using-python-part-2-comprehensive-python-tutorial)** **[Srs 3](https://hive.blog/python/@bob-elr/become-a-python-developer-build-on-algorand-blockchain-day-3)** 
**[Srs 4](https://hive.blog/python/@bob-elr/day-4-creating-first-transaction-on-algorand-testnet-using-python-dictionary-and-conditions-in-python)** **[Srs 5](https://hive.blog/algorand/@bob-elr/day-5-getting-started-with-python-using-algorand-private-key-mnemonic-phrase-relationship-keyword-explained)** **[Srs 6](https://hive.blog/algorand/@bob-elr/gswpualgorand-day-6-code-refactoring-creating-modules-in-python-transfer-algo-between-three-accounts-simultaneously-and-checking)**</center>

****

<center>Multi-Signature  Account</center>
-----

<h3>A fictional case study</h3>


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.

<center>Disappointingly, bank would not grant their request unless they would provide a certificate indicating legal wedding as a couple. But they were only trying to pool resources towards tying the nuptial nut. In nutshell, they couldn't find a way around it. She claimed to loved him but would not risk saving to his account. Same with him. Even if he had succumb to saving to her account, The breakup would have left him with lasting pain. But what if that happened? 
On Algorand, several real-life issues have their paired solutions. MultiSig wallet would have been their best solution if awareness had reached them.</center>

****

<center><h3>Experimenting real-life use case with Algorand solution</h3></center>

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.

<center>Ok great, I understand what they need perfectly. Let's get to work.</center>

****

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.


<center>![image.png](https://images.hive.blog/DQmVZdFDCGAXzKDY7y3Cgkxh5kWZV8W9LY3r99gH3xqbUG3/image.png)</center>

<center>Using our usual default account as Raymond's fiancee's account. We created an account for her and set it to **`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.</center>

* Next we we call our already established **`connectToNetwork()`** function from **`connect.py`** file.
* Get suggested parameters.
* Call **`generateAccounts()`** function which launches 3 new accounts from **`generateaccount`** module, stores the result in **`accounts`** dictionary. Line **`16`** does this jobs and we only print the result to the console from **`17`**.
* **`req`**  is number of signatories to the Multisig wallet.
* **`21`** is required by inbuilt `Multisig` class that initiates `multisig` function.
* From the 3 accounts we created from `16`, we assigned first account as Raymond's account address and its private key in **`23`**.

<center>![image.png](https://images.hive.blog/DQmU1RBnpZce9VoWUCTZUGzaVEFLZ72pusJHhCsCtSME3eW/image.png)</center>

* In line **`27`**, we registered both parties' addresses as the required number of signatories.
*  They will be able to withdraw from **`savingsAccount`** to **`spendAccount`** only if both parties signatures are collected from **`37`** and **`38`**, enjoined in **`36`** and broadcast in **`39`** 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 in **`33`**.
* **`35`** specifies the structure of fund withdrawal from **`savingAlcAddr`** (multisig account) to **`spendAccount`** with the amount to withdraw waiting to be signed

****
<center>Interestingly, spending on trivialities will be as result of consensus ad idem. They can decide to save toward paying house rent, starting a business or project or do meaningful things. Business partners could see this as a way of resolving inherent partnership issues that the native or borrowed laws struggle to resolve. We didn't demand for any certificate except a good consideration(payment). The protocol removes the middleman, acts as trustee and it can be trusted with regards to what it is programmed to do.</center>

****

<center>**<h3>How To Create Transaction Group.</h3>**</center>

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. 

<center>We will reuse most of our modules but for the **`pythonTutorial.py`** file. I created a file - **`pythonMain_day7.py`** to execute it.</center>

****

<center>**<h3>What changed!.</h3>**</center>

* Moved transaction parameters to a function **`create_transaction`** in a new file **`createTransaction.py`**  

<center>![image.png](https://images.hive.blog/DQmQ3LLARMgQue6axfGHMpHeRHRDt5s1Boxa67u7D4reBKn/image.png)
</center>

****

* In **`sendtransaction.py`** file, created three different transactions from three accounts generated from **`create_transaction()`**  we imported - lines **`12`** to **`14`**, grouped them together - **`17`** to **`19`**. 

* **`16`**, the grouping is done using a list of transaction IDs generated from hash of calculating the trio. 

 * **`21`** to **`23`** signs each of transactions with paired private keys.
* Then we broadcast the group to the network enclosed as array of objects in a list.

![image.png](https://images.hive.blog/DQmeCVrjnMPzMNzo8GDPvtgpuyszQ9N5KaprEWytss9gmo1/image.png)

****

<center>Here we execute the files. Try it by copying the full codes from **[github](https://github.com/bobeu/pythonTutorial)**. Please leave comment if you have any concern.</center>

<center>![image.png](https://images.hive.blog/DQmWyBq2VpJ7TmfQhLeoF1Jer7q2YmkmrpuXAuwgm8kkfow/image.png)</center>

****
<center><h3>Output</h3></center>

<center>![image.png](https://images.hive.blog/DQmRwTyyW1e11qm4KK4ypRunjktuKj5rhRtCpgyMgerP4w7/image.png)</center>


****

<center><h3>Likely Error You Might Encounter</h3></center>

<center>While practicing, you may like experience this error. Its an indication you are trying to send token from a newly generated account or account with no enough balance. You either did not give enough room for confirmation before printing out the current account status like I did here. Solution is to create enough room for confirmation which is usually around 5 seconds.<center>

<center>![image.png](https://images.hive.blog/DQmermKEb9wM8Kwn5DwsqyNTqafwKuyY9bniwaCE9893WEy/image.png)</center>

****

<center>Happy coding. stay tuned for more tutorials.</center>

<center>Find more **[resources](https://developer.algorand.org/)**</center>
👍  , , , , , , , , ,
properties (23)
authorbob-elr
permlinkgswpua-day-7-multisigw-account-concept-with-example-and-use-case-how-to-create-a-transaction-group-and-likely-error-with
categoryalgorand
json_metadata{"app":"hiveblog/0.1","format":"markdown","image":["https://images.hive.blog/DQmPT8qfqANVCaXCoKwt3oTLekNgo2wEatsCnkWVSai5Pyv/image.png","https://images.hive.blog/DQmVZdFDCGAXzKDY7y3Cgkxh5kWZV8W9LY3r99gH3xqbUG3/image.png","https://images.hive.blog/DQmU1RBnpZce9VoWUCTZUGzaVEFLZ72pusJHhCsCtSME3eW/image.png","https://images.hive.blog/DQmQ3LLARMgQue6axfGHMpHeRHRDt5s1Boxa67u7D4reBKn/image.png","https://images.hive.blog/DQmeCVrjnMPzMNzo8GDPvtgpuyszQ9N5KaprEWytss9gmo1/image.png","https://images.hive.blog/DQmWyBq2VpJ7TmfQhLeoF1Jer7q2YmkmrpuXAuwgm8kkfow/image.png","https://images.hive.blog/DQmRwTyyW1e11qm4KK4ypRunjktuKj5rhRtCpgyMgerP4w7/image.png","https://images.hive.blog/DQmermKEb9wM8Kwn5DwsqyNTqafwKuyY9bniwaCE9893WEy/image.png"],"links":["https://www.google.com/search?q=day+7&sxsrf=ALeKk00UikfAmn-bc-yjBJISP1qAJtM73A:1590866122338&tbm=isch&source=iu&ictx=1&fir=sC2IrzNVwJPKRM%253A%252CCwCqWHdcd6GgpM%252C_&vet=1&usg=AI4_-kRUM-jXis2qgPfzFGSjeTgcaJUCKg&sa=X&ved=2ahUKEwiKoO2QptzpAhUJkRQKHcv7C8EQ9QEwAXoECAEQKg#imgrc=sC2IrzNVwJPKRM:","https://hive.blog/python/@bob-elr/python-become-a-programmer-and-build-real-world-traditional-or-decentralized-applications-on-platforms-such-algorand-blockchain","https://hive.blog/python/@bob-elr/build-on-algorand-blockchain-using-python-part-2-comprehensive-python-tutorial","https://hive.blog/python/@bob-elr/become-a-python-developer-build-on-algorand-blockchain-day-3","https://hive.blog/python/@bob-elr/day-4-creating-first-transaction-on-algorand-testnet-using-python-dictionary-and-conditions-in-python","https://hive.blog/algorand/@bob-elr/day-5-getting-started-with-python-using-algorand-private-key-mnemonic-phrase-relationship-keyword-explained","https://hive.blog/algorand/@bob-elr/gswpualgorand-day-6-code-refactoring-creating-modules-in-python-transfer-algo-between-three-accounts-simultaneously-and-checking","https://github.com/bobeu/pythonTutorial","https://developer.algorand.org/"],"tags":["python","ocd","programming","multisig"]}
created2020-05-30 19:14:42
last_update2020-06-05 12:17:15
depth0
children0
last_payout2020-06-06 19:14:42
cashout_time1969-12-31 23:59:59
total_payout_value0.026 HBD
curator_payout_value0.026 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length9,372
author_reputation4,312,688,255,499
root_title"GSWPUA-Day-7: Multisig account concept with example and use case, how to create a transaction group and likely error with description"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,679,500
net_rshares193,968,891,968
author_curate_reward""
vote details (10)