Wallet
A Wallet manages a single private key which is used to sign transactions, messages and other common payloads.
This class is generally the main entry point for developers that wish to use a private key directly, as it can create instances from a large variety of common sources, including raw private key, BIP-39 mnemonics and encrypted JSON wallets.
Extends
BaseWallet
Constructors
new Wallet()
Create a new wallet for the private key
, optionally connected to provider
.
Parameters
Parameter | Type | Description |
---|---|---|
key | string | SigningKey | The private key. |
provider ? | null | Provider | The provider to connect to. |
Returns
Overrides
BaseWallet.constructor
Source
Properties
Property | Modifier | Type | Description | Inherited from |
---|---|---|---|---|
#address | private | string | The wallet address. | BaseWallet.#address |
#signingKey | private | SigningKey | The signing key used for signing payloads. | BaseWallet.#signingKey |
provider | readonly | null | Provider | The provider this signer is connected to. | BaseWallet.provider |
Accessors
address
The address of this wallet.
Returns
string
Source
privateKey
The private key for this wallet.
Returns
string
Source
signingKey
The SigningKey used for signing payloads.
Returns
Source
Methods
connect()
Connects the wallet to a provider.
Parameters
Parameter | Type | Description |
---|---|---|
provider | null | Provider | The provider to connect to. |
Returns
The connected wallet.
Overrides
BaseWallet.connect
Source
encrypt()
Resolves to a JSON Keystore Wallet encrypted with password
.
If progressCallback
is specified, it will receive periodic updates as the encryption process progresses.
Parameters
Parameter | Type | Description |
---|---|---|
password | string | Uint8Array | The password to encrypt the wallet with. |
progressCallback ? | ProgressCallback | An optional callback to keep the user informed. |
Returns
Promise
<string
>
The encrypted JSON wallet.
Source
encryptSync()
Returns a JSON Keystore Wallet encrypted with password
.
It is preferred to use the async version instead, which allows a ProgressCallback to keep the user informed.
This method will block the event loop (freezing all UI) until it is complete, which may be a non-trivial duration.
Parameters
Parameter | Type | Description |
---|---|---|
password | string | Uint8Array | The password to encrypt the wallet with. |
Returns
string
The encrypted JSON wallet.
Source
getAddress()
Returns the address of this wallet.
Parameters
Parameter | Type | Description |
---|---|---|
_zone ? | string | The zone (optional). |
Returns
Promise
<string
>
The wallet address.
Inherited from
BaseWallet.getAddress
Source
signMessage()
Signs a message.
Parameters
Parameter | Type | Description |
---|---|---|
message | string | Uint8Array | The message to sign. |
Returns
Promise
<string
>
The signed message.
Inherited from
BaseWallet.signMessage
Async
Source
signMessageSync()
Returns the signature for message
signed with this wallet.
Parameters
Parameter | Type | Description |
---|---|---|
message | string | Uint8Array | The message to sign. |
Returns
string
The serialized signature.
Inherited from
BaseWallet.signMessageSync
Source
signTransaction()
Signs a transaction.
Parameters
Parameter | Type | Description |
---|---|---|
tx | QuaiTransactionRequest | The transaction request. |
Returns
Promise
<string
>
The signed transaction.
Inherited from
BaseWallet.signTransaction
Source
signTypedData()
Signs typed data.
Parameters
Parameter | Type | Description |
---|---|---|
domain | TypedDataDomain | The domain of the typed data. |
types | Record <string , TypedDataField []> | The types of the typed data. |
value | Record <string , any > | The value of the typed data. |
Returns
Promise
<string
>
The signed typed data.
Inherited from
BaseWallet.signTypedData
Async
Source
fromEncryptedJson()
Creates (asynchronously) a Wallet by decrypting the json
with password
.
If progress
is provided, it is called periodically during decryption so that any UI can be updated.
Parameters
Parameter | Type | Description |
---|---|---|
json | string | The JSON data to decrypt. |
password | string | Uint8Array | The password to decrypt the JSON data. |
progress ? | ProgressCallback | An optional callback to keep the user informed. |
Returns
Promise
<Wallet
>
The decrypted wallet.
Source
fromEncryptedJsonSync()
Creates a Wallet by decrypting the json
with password
.
The fromEncryptedJson method is preferred, as this method will lock up and freeze the UI during decryption, which may take some time.
Parameters
Parameter | Type | Description |
---|---|---|
json | string | The JSON data to decrypt. |
password | string | Uint8Array | The password to decrypt the JSON data. |
Returns
The decrypted wallet.
Source
Was this page helpful?