Most operations in Neo blockchain are related to accounts. A wallet is the collection of accounts that includes one or multiple accounts. This document contains the following topics:
The basic concepts and operations of accounts and wallets
The method WalletAPI ,which encapsulates wallet-related interfaces to provide the functions of balance inquiry, GAS claim, and transfer.
Account and Wallet
Account
An account is the user identity in Neo, which is essentially a private and public key pair ( KeyPair ) .
Private Key
Private key is an authorization tool used to sign transactions. Having a private key means you own an account that you can handle all the assets in it. The private key is essentially a 32-bit byte array that can be represented as a hexadecimal string, for example:
WIF is another string representation of the private key, which is equivalent to the private key. For example, the above private key is represented as the following WIF:
The public key verifies the signature of the private key. It corresponds to the ECPoint type in Neo. The public key can be calculated with the private key. Typically it is a 66-digit hexadecimal string:
ScriptHash, corresponding to UInt160 in Neo, is essentially a 20-bit byte array generated from the public key by script construction and hash algorithm. Since the hash algorithm is not reversible, the public key cannot be calculated backwards from the script hash. ScriptHash is usually expressed as a reversed hexadecimal string in big-endian order: "0xb0a31817c80ad5f87b6ed390ecb3f9d312f7ceb8"
Address
Address is another string form of ScriptHash and can be transformed to or from ScriptHash. As the unique identifier of the account, address is the most commonly used account form. It is similar to the account number for a traditional account, when you transfer money you transfer it to a specified address. A common address format is: "Ncm9TEzrp8SSer6Wa3UCSLTRnqzwVhCfuE"
Wallet
Wallet is a collection of accounts. NEP6 is the most commonly used wallet standard in Neo. A NEP6 wallet can be serialized into a JSON file, in which the encrypted account private key is saved. The corresponding password is required to decrypt the private key.
Here is an example:
Create a new NEP6 wallet with an account and save as JSON file:
Read the NEP6 wallet from the JSON file and decrypt the account:
Using WalletAPI
Initialization
Initializing WalletAPI :
Inquiring balance
The type of account balance is usually BigInteger, which is a representation after rounding the decimal part. It needs to be divided by Factor to get the actual Token amount.
Inquiry NEP-17 asset balance using the string parameter:
or using the parameter of ScriptHash type:
In Neo N3 NEO and GAS are both NEP17 assets with the fixed scripthash. Here we provide a simpler interface:
Claiming GAS
In Neo N3 GAS is automatically claimed when NEO is transferred. You can construct a transaction transferring to yourself to claim GAS.
First check the claimable GAS amount at current address:
or use ScriptHash of the account to check:
Construct a transaction sending NEO to yourself:
or use KeyPair :
Asset Transfer
WalletAPI encapsulates transfer methods of NEP-17 assets.