For those to lazy to use Google Translate.
In my previous post, I introduced python-bitshares, a powerful python library for manipulating the bitshares blockchain. And introduced python-bitshares installation and run a simple example, and a brief analysis of python-bitshares RPC with bitshares relationship.
This section we continue to learn python-bitshares.
Import private key
In Uptick's introductory article, to make better use of uptick, we added the bitshares account's private key to the uptick wallet. In fact, the wallet function is implemented and accessed at this level of python-bitshares. uptick just encapsulates the related functionality.
In order to facilitate our follow-up study, we also need to add the private key to the python-bitshares local wallet. How to get the account private key, you can refer to the corresponding steps in this article:
Another Swiss army knife? Uptick first experience (b): import the private key
Use uptick to import the private key
If we installed uptick, then you can use uptick import private key, very convenient. How to import, in this article has done a detailed introduction, will not repeat them.
But my direct installation of python-bitshares does not include uptick, so i can not use uptick to import the private key.
Use the code to import the private key
We need to create a wallet before importing the private key
from bitshares import BitShares
bitshares = BitShares (node = "wss: //openledger.hk/ws")
bitshares.wallet.create ("passwd")
The above code creates a local wallet and sets the password to passwd
(Password is for example only, for safety reasons, the actual use, it is recommended to set a complex password)
Before creating a wallet, we first need to unlock the wallet:
bitshares.wallet.unlock ("passwd")
After unlocking the wallet, we can import the private key
bitshares.wallet.addPrivateKey ("5XXXXXXXX")
After successful implementation, the private key is imported into the wallet.
Unlock using the UNLOCK environment variable
In the example above, we used it
bitshares.wallet.unlock ("passwd")
To unlock the wallet.
Hard-coded passwords in the code is not a good habit, if we have more than one code, and then need to change the password, this must be a very headache.
So what other ways to specify the password?
That is to set the environment variables, such as in my system,
export UNLOCK = "passwd"
For each entry into force, can be added to the corresponding user's. Bashrc file
This way we can eliminate the need to hard-code passwords in programs and unlock () each time.
Wallet other features
In general, all python-bitshares and wallet deal, we should be transparent as well. Occasionally, however, we may also need to manipulate the wallet directly, for example, to see which users are in the wallet or to read the private key of a corresponding user from the wallet.
Some of the functions that may be used are as follows:
changePassphrase, change the password
getAccounts, lists all the users in the wallet
getPublicKeys, lists all the public key in the wallet
getPrivateKeyForPublicKey, list the corresponding private key of the public key.
For more functions and functions, please refer to:
https://github.com/xeroc/python-bitshares/blob/master/bitshares/wallet.py
Wallet storage location
Sometimes we may need to migrate the wallet to other accounts, this time one by one to re-add the private key is a very troublesome thing, if you can directly migrate the wallet file just fine.
Different systems, the wallet storage location is different
Under Linux, the wallet file path is: ~ / .local / share / bitshares / bitshares.sqlite
Can be seen from the name is a sqlite database, the library also contains some default parameters like settings, this section is unknown chat.
to sum up
python-bitshares provides an encrypted local wallet, so that we can use it more convenient. This article describes the python-bitshares wallet-related operations, including the following:
Create a wallet
Unlock the wallet
Import private key
Use the UNLOCK environment variable
Other functions of the wallet
Wallet storage location
Reference Information
Python-bitshares learning by side (A): Introduction and installation
https://github.com/xeroc/python-bitshares