Tutorial 3 - Running jigs on Bitcoin Mainnet, Part 2
|
ALERT: This Page is Outdated and Waiting for Update The current way of testing the RUN library to create tokens and jigs is to open the devtools console at Runcraft.io, then head over to creating and loading jigs. |
In Part 1, you learned how to upload code to the Bitcoin network and inspect the transactions on a block explorer. In Part 2, you’ll learn how to backup your funds and reload your saved jigs.
Contents
Getting started
This tutorial continues where Part 1 finished, so you’ll need to have your Firefox browser tab with the same Console session.
In RUN, the purse and the owner are separate bitcoin accounts:
You store money with the purse and you store jigs with the owner. If you gave them personified roles, the purse would be a banker persona and the owner would be a dog walker persona. The owner as a dog walker can give instructions to the jigs, but he doesn't have any money. The purse as a banker character provides the funds.
Keeping the two separate helps performance as well as security.
Each one has a separate public address you can see on the block explorer and its own separate private key that allows you to make new transactions.
Searching for the jig owner address
At the end of Part 1 tutorial, you searched for a location on the RUN Explorer:
The address in the owned by section is the owner.
Your transaction IDs and addresses will look different than mine because they are unique to you. Don’t worry, you will still complete the tutorial--just use the screenshots as your guide.
Click on the address in the owned by section (highlighted in green above):
The RUN Explorer shows that this address owns one jig, a Dragon, that was recently updated.
You can verify if the address you see is really your owner address in the Console.
Type the following code:
run.owner.address
The Console will return the address:
Yes! Both addresses match as expected. 😅
Now copy the address and search for it in the other tab with the WhatsOnChain block explorer:
The address was involved in two transactions. The first transaction is the one that uploaded the class definition and the second transaction is the one that updated the instance by calling the setName(name) method.
You have already seen both addresses in action:
- 1HM…56R is the
owneraddress that controls the jigs. Each output only has dust, 546 satoshis, so that it can perform the next update on the jigs it owns. - 1PK…qst is the
purseaddress that controls the money. It holds 700,000 satoshis to help you finance all the future updates you will perform in RUN.
Getting the owner private key
You already retrieved the private key for the purse address like 14e…UZc in the beginning of the Part 1 tutorial. That private key allows you to restore the purse after you end this session.
You will also want to restore your saved jigs. You wouldn’t want to lose access to them when you close the browser.
To get the private key for the owner you use the same pattern as the purse. Navigate back to the tab with the Console and type the following code:
run.owner.privkey
The Console will print out your private key:
Treat the private key with care. Don’t share it with anyone and store it securely encrypted in a password manager. If anyone gets access to the owner private key then they control your jigs and can mess with them.
Now that you’ve got the private keys for both the purse and the owner, you can fully restore your Console session next week when you’re taking another tutorial. 😉
Restoring the purse and owner with private keys
Make a new browser tab and open the RUN Homepage. A new tab will have a different Console session than all your previous work. It is a bit like if you closed the browser and wanted to resume working again later.
Open the Console in the new tab by pressing Control-Shift-K on Windows or Command-Option-K on macOS.
Open your password manager, and locate your purse private key and your owner private key. Then type the following code into the Console, replacing the fill-in-the-blank underscore characters with the actual private keys:
const run = new Run({purse: "_privkey_", owner: "_privkey_"})
That code creates a new instance of Run, but instead of giving you a random purse and owner it restores your previous ones.
Check if they restored correctly. First type this code:
run.owner.address
Then type this code:
run.purse.address
The Console will print out both addresses:
It worked! You will have different addresses than me, but if you remember back to the beginning of this tutorial, those addresses were the ones you saw in the block explorer screenshot.
Importing purse private key in Electrum SV
Your purse is just like any other bitcoin wallet, so you can import it into other wallet apps.
Exercise caution: Don’t import yourowneraddress into money wallet apps. Most wallet apps don’t know how to read jigs… yet. 😉 If you import yourownerinto a wallet app meant for money, the wallet app will try to spend the bitcoin output associated with your jig. Spending the output would destroy your jig. So long story short, only import yourpurseinto wallet apps, not theowner. One day soon, wallet apps will know how to differentiate between a jig wallet and a bitcoin money wallet.
First, download Electrum SV. Select the correct version for your operating system:
Install it as you would any other app.
Note for Mac users: On the Mac, after the install, you’ll need to open the Applications folder in Finder app. Then Control-Click the Electrum SV app and click Open in the context menu. A Confirm dialog will appear. Click Open. This workflow stems from Apple trying to keep you safe by making it a little harder to open untrusted apps.
Once you get Electrum SV open, it will display any previous wallets that you’ve had before:
If you see this dialog, you’ll need to unlock the wallet by typing the password you set up. Then click Next.
Now you can access the Menu items:
From the Menu, select File ▸ New/Restore. Give your wallet a descriptive name, run_tutorials:
Click Next.
The wizard will ask what you kind of wallet you would like to create. Select Import Bitcoin addresses or private keys, then click Next.
Navigate to your browser tab with the Console open.
Copy your purse private key from the new Run() initialization:
Once you’ve copied the private key, paste it into Electrum SV:
Click Next.
The wizard will offer you the opportunity to encrypt the wallet with a password. Choose a strong one:
Click Next.
Electrum SV will show the history:
From here you can verify how much money each RUN transaction uses. The first transaction to write the class definition used 1697 satoshis, while the second transaction to update the jig with setName(name) only used 531 satoshis.
Over time, Bitcoin mining fees will drop as more people use the network. It will be a bit like how IKEA can afford to sell furniture so cheaply. They make money with volume, by selling lots of items at a low margin. RUN will always use the best price it can for each transaction. As mining fees drop over time, the transactions RUN creates will become even cheaper, unlocking more use cases.
When you decide that you’re done using RUN, you can use Electrum SV to send the money away from your purse to another wallet address or to another wallet app like HandCash.
Where to go from here
You’ve learned all about how to restore both your jigs and your money.
Now you can work on building complex jigs over many weeks. The only limit is your creativity. Discover all the things you can accomplish by diving into the Docs.
When you’re ready to move on to more advanced usage of RUN, continue to the next tutorial in the Digital Pet series: Tutorial 4 - Running a Pay Server on Bitcoin Testnet