cardano_wallet_sdk library

Classes

AdaDateTime
Convert Cardano block time (secondsSinceEpoch in UTC) to DateTime and back.
AdaDateTimeDecoder
AdaDateTimeEncoder
AdaFormattter
ADA-specific currency formatter that expects all curreny to be in lovelace and converts it to ADA (1 ADA = 1,000,000 lovelace). Compact formatters replace groups of zeros with quantity abbreviation suffixes (i.e. K=thousond, M=million, B=billion & T=trillion). The simple formatters group zeros into threes. Decimal digits defaults to 6 places. The currency factory method allows complete customization.
AssetRequest
an single asset name and value under a MultiAsset policyId
Bip32KeyPair
Private/signing and public/varification key pair.
Block
Block record
BlockchainAdapter
High-level abstraction to blockchain tailored towards balences and transactions.
BlockchainAdapterFactory
Provides a properly configured BlockchainAdapter for the requirested network. Instances are cached and should be reused because they often cache invariant blockchain data allowing for faster updates.
BlockchainCache
The cache holds invariant block chain data.
BlockfrostApiKeyAuthInterceptor
BlockfrostBlockchainAdapter
Loads BlockFrost data into this wallet model
CardanoBlockchainExplorer
Cardano Blockchain Explorer url generator for common blockchain web pages. Supports both mainnet and testnet networks and i18n language translations.
CardanoScanBlockchainExplorer
Cardano Scan Blockchain Explorer url generator for common blockchain web pages. Supports both mainnet and testnet networks.
CBORMetadata
Allow arbitrary metadata via raw CBOR type. Use MapBuilder and ListBuilder instances to compose complex nested structures.
CoinGeckoApiFix
Coin Gecko service to get real-time exchange trading values.
CoingeckoPriceService
CoinSelection
CoinSelectionError
CurrencyAsset
CurrencyAssetMetadata
HdWallet
This class implements a hierarchical deterministic wallet that generates cryptographic keys and addresses given a root signing key. It also supports the creation/restoration of the root signing key from a set of nmemonic BIP-39 words. Cardano Shelley addresses are supported by default, but the code is general enough to support any wallet based on the BIP32-ED25519 standard.
LinearFee
Used in calculating Cardano transaction fees.
MultiAssetBuilder
Special builder for creating ShelleyValue objects containing multi-asset transactions.
MultiAssetRequest
Native Token multi-asset container.
MultiAssetRequestBuilder
Special builder for creating ShelleyValue objects containing multi-asset transactions.
Price
Used for tracking currency trading pair prices (i.e. ADA to USD).
PriceService
not being used at the moment. see price_polling_service
RawTransaction
Raw transactions mirror the data on the blockchain. Amounts in lovelace.
RawTransactionImpl
ReadOnlyWallet
Cardano read-only wallet that holds transactions, staking rewards and their associated addresses. A public, read-ony wallet can be built given a stakingAddress and a networkId. All blockchain data retrieval is delegated to the BlockchainAdapter.
ReadOnlyWalletImpl
Given a stakingAddress, generate a read-only wallet with balances of all native assets, transaction history, staking and reward history.
ShelleyAddress
ShelleyAddressKit
Everything you need to add a spend (or change) address to a UTxO transaction.
ShelleyAsset
an single asset name and value under a MultiAsset policyId
ShelleyMultiAsset
Native Token multi-asset container.
ShelleyNativeScript
TODO ShelleyNativeScript is just a place-holder for these concrete classes: ScriptPubkey, ScriptAll, ScriptAny, ScriptAtLeast, RequireTimeAfter, RequireTimeBefore
ShelleyTransaction
outer wrapper of a Cardano blockchain transaction.
ShelleyTransactionBody
Core of the Shelley transaction that is signed.
ShelleyTransactionInput
Points to an UTXO unspent change entry using a transactionId and index.
ShelleyTransactionOutput
Address to send to and amount to send.
ShelleyTransactionWitnessSet
this can be transaction signatures or a full blown smart contract
ShelleyValue
Can be a simple ADA amount using coin or a combination of ADA and Native Tokens and their amounts.
ShelleyVkeyWitness
A witness is a public key and a signature (a signed hash of the body) used for on-chain validation.
StakeAccount
StakePool
StakePoolMetadata
StakeReward
TransactionAmount
Amount and type for a specific native token.
TransactionBuilder
This builder manages the details of assembling a balanced transaction, including fee calculation, change callculation, time-to-live constraints (ttl) and signing.
TransactionInput
Inputs or outputs for a given transaction.
TransactionOutput
Wallet
Extend ReadOnlyWallet with signing and transactional capabilities. Signing (private), key, verify (public) key and address generation is handled by the HdWallet instance.
WalletBuilder
This builder creates both read-only and transactional wallets from provided properties. Generated from a staking addresses, read-only wallets can show a balance and recieve funds, but can't sign or send payment transactions. Transactional wallets require a cryptographic private/signing key and can sign and send payment transactions. Alternatively, private keys can be generated from a 24-word mnemonic phrase. A BlockchainAdapter is used to communicate with the blockchain, it defaults to BlockfrostBlockchainAdapter for which an authorization adapter key must be provided for the target network. Each wallet type has a sync-varient build method that will load it's transactions and calculate the current balance before returning. Finally, all wallets must choose to run on either the mainnet or testnet.
WalletCache<T>
Wallet cache interface.
WalletCacheMemory<T>
Implements an in-memory version of WalletCache.
WalletImpl
Build transactional wallet by combining features of HdWallet, TransactionBuilder and ReadOnlyWallet.
WalletTransaction
Transaction from owning wallet perspective (i.e. filters raw transaction deposits and withdrawals specific to owned addresses).
WalletTransactionImpl
WalletUpdate
Pass-back object used to update existing or new wallets.
WalletValue<T>

Enums

AddressType
Encapsulates Shelley address types. Handles proper bech32 encoding and decoding mainnet and testnet addresses.
CoinSelectionErrorEnum
CredentialType
NetworkId
The Cardano testnet and mainnet are two independent blockchains and this value determines which one your code will run on.
TemperalSortOrder
TransactionStatus
TransactionType

Extensions

ShelleyTransactionBodyLogic on ShelleyTransactionBody
Handle balance checks and generating/modifying the correct change output so that the sum of inputs and output is zero (i.e. is balanced).
ShelleyTransactionLogic on ShelleyTransaction
Extends ShelleyTransaction to handle signature verification.
TransactionScanner on RawTransaction
Transaction extension - wallet attribute collection methods

Constants

adaDateTime → const AdaDateTime
baseDiscrim → const int
changeRole → const int
role 1=internal/change
cip16ExtendedSigningKeySize → const int
Extended private key size in bytes
cip16ExtendedVerificationgKeySize → const int
Extended public key size in bytes
coinZero → const Coin
placeholder for future BigInt.zero
defaultAccountIndex → const int
Is zero. This returns the base account address.
defaultAddressIndex → const int
defaultAddrHrp → const String
defaultCoinSelectionLimit → const int
defaultCoinType → const int
Coin-type for Cardano ADA. Ada Lovelace's year of birth.
defaultFee → const int
default fee for simple ADA transaction
defaultLinearFee → const LinearFee
fee calculation factors TODO update this from blockchain TODO verify fee calculation context of this values
defaultPurpose → const int
Default purpose. The year Ada Lovelace passed away. Reference: CIP-1852
defaultRewardHrp → const String
enterpriseDiscrim → const int
firstOneSecondEpoch → const int
firstSlotOfEpoch208 → const int
hardenedOffset → const int
Hardended chain values should not have public keys. They are denoted by a single quote in chain values.
lenHackAddition → const int
lovelaceAssetId → const String
lovelaceHex → const String
'lovelace' encoded as a hex string (i.e. str2hex.encode('lovelace') or '6c6f76656c616365').
millisecondsPerEpoch0_207 → const int
millisecondsPerEpochGt207 → const int
millisecondsPerSlot0_207 → const int
millisecondsPerSlotGt207 → const int
minFeeA → const int
minFeeB → const int
paymentRole → const int
role 0=external/payments
pointerDiscrim → const int
rewardDiscrim → const int
secretKeyLength → const int
slotsPerEpoch0_207 → const int
slotsPerEpochGt207 → const int
stakingRole → const int
role 2=staking
testnetHrpSuffix → const String

Properties

epoch0Slot0Utc DateTime
final
epoch0Slot0UtcMs int
final
hex2str Codec<String, String>
final
lovelacePseudoAsset CurrencyAsset
Pseudo ADA asset instance allows principal asset to be treated like other native tokens. Blockfrost returns 'lovelace' as the currency unit, whereas all other native tokens are identified by their assetId, a hex string. For consistency, 'lovelace' unit values must be converted to lovelaceHex strings.
final
str2hex Codec<String, String>
Various encoders, decoders and type converters.
final

Functions

alwaysUnused(dynamic _) bool
UnusedAddressFunction that will always return true (i.e. You'll always get the base spend/change address).
b2s(List<int> bytes, {String prefix = 'bytes'}) String
Dump byte array. Example: bytes20: 244,155,227,187,150,186,199,61,202,241,76,208,46,192,219,56,241,103,253,67
bech32ShelleyAddressFromBytes(Uint8Buffer bytes) String
Convert bytes to bech32 Shelley address. TODO move to shelley_address.dart
blake2bHash(List<int> stringBytes, {required int digestSize}) List<int>
Base blake2b hash function can produce hashes of arbirary size.
blake2bHash160(List<int> stringBytes) List<int>
blake2bHash224(List<int> stringBytes) List<int>
blake2bHash256(List<int> stringBytes) List<int>
calculateFingerprint({required String policyId, required String assetNameHex, String hrp = 'asset'}) String
given a asset policyId and an assetName in hex, generate a bech32 asset fingerprint
convertBits(List<int> data, int fromWidth, int toWidth, bool pad) List<int>
dioCall<T extends Object>({required NetworkRquest request, OneArgFunction? onSuccess, ResponseFunction? onError, String? errorSubject}) Future<Result<T, String>>
DIO network request wrapper that handles checking response and packaging result or error message. Returns an oxidizer Result.
epochToDateTime({int epoch = 0}) DateTime
convert epoch to UTC timestamp
epochToMilliseconds({int epoch = 0}) int
convert epoch to unix time in milliseconds
harden(int index) int
Hardens index, meaning it won't have a public key
hexFromShelleyAddress(String bech32, {bool uppercase = false}) String
Convert bech32 address payload to hex string. Optionaly uppercase hex string. TODO move to shelley_address.dart
hexFromUnit8Buffer(Uint8Buffer bytes) String
isHardened(int index) bool
Returns true if index is hardened.
largestFirst({required List<WalletTransaction> unspentInputsAvailable, required List<MultiAssetRequest> outputsRequested, required Set<ShelleyAddress> ownedAddresses, int coinSelectionLimit = defaultCoinSelectionLimit, bool logSelection = false}) Future<Result<CoinSelection, CoinSelectionError>>
signEd25519({required Uint8List message, required Uint8List privateKey}) Uint8List
Cryptographic signature methods.
signEd25519Extended({required Uint8List message, required Uint8List privateKey, required Uint8List publicKey}) Uint8List
Sign a message with a ed25519 expanded private key and return signature
simpleMinFee({required ShelleyTransaction transaction, LinearFee linearFee = defaultLinearFee}) Coin
calculate transaction fee based on transaction lnegth and minimum constant
slotToDateTime({int slot = 0}) DateTime
convert slot to UTC timestamp
slotToMilliseconds({int slot = 0}) int
convert slot to unix time in milliseconds
translateErrorMessage({required DioError dioError, String? subject}) String
blockfrost error codes to user readable messages
uint8BufferFromHex(String hex, {bool utf8EncodeOnHexFailure = false}) → Uint8Buffer
convert hex string to Uint8Buffer. Strips off 0x prefix if present.
uint8ListFromBytes(List<int> bytes) Uint8List
Convert List
unit8BufferFromBytes(List<int> bytes) → Uint8Buffer
Convert List
unit8BufferFromShelleyAddress(String bech32) → Uint8Buffer
Convert bech32 address payload to hex adding network prefix. TODO move to shelley_address.dart
validAda({required String ada, int decimalPrecision = 6, bool allowNegative = false, bool zeroAllowed = false}) → Result<String, String>
If ADA string is all digits, not negative and the correct decimal precision, then the normalized correct form is returned. If it's not legal, then an explanation is returned in the error message.
validBech32({required String bech32, required List<String> hrpPrefixes, int? dataPartRequiredLength}) → Result<String, String>
if bech32 string has the correct prefix, '1' seperator, legal data characters and optionaly correct length, the normalized correct form is returned. If it's not legal, then an explanation is returned in the error message.
validMnemonic({required String phrase, int requiredNumberOfWords = 24}) → Result<String, String>
If the mnemonic or recovery phrase has all legal characters and the requiredNumberOfWords, then the normalized correct form is returned. If it's not legal, then an explanation is returned in the error message.
validMnemonicWord(String word) bool
Return true if a valid mnemonic word
validMnemonicWords(List<String> words) → Result<bool, String>
Return true if a all the provided mnemonic words are valid.
verifyEd25519({required Uint8List signature, required Uint8List message, required Uint8List publicKey}) bool

Typedefs

AssetId = String
Native Token policyId appended to hex encoded coin name. ADA has no policyId so its assetId is just 'lovelace' in hex: '6c6f76656c616365'. Simalur to 'unit' but 'lovelace' is not hex encoded.
Bech32Address = String
String representation of bech32 address
BlockHashHex = String
Hex encoded block hash ID
Coin = int
Represents ADA amount in lovelace.
CoinSelectionAlgorithm = Future<Result<CoinSelection, CoinSelectionError>> Function({int coinSelectionLimit, bool logSelection, required List<MultiAssetRequest> outputsRequested, required Set<ShelleyAddress> ownedAddresses, required List<WalletTransaction> unspentInputsAvailable})
Coin selection is the process of picking UTxO inputs to perticipate in a spending transaction. There is a dedicated Cardano Improvement Proposal that this implementation is attempting to follo in spirit:
CurrentEpochFunction = Future<int> Function()
MinFeeFunction = Coin Function({LinearFee linearFee, required ShelleyTransaction transaction})
NetworkRquest = Future<Response> Function()
OneArgFunction = void Function(dynamic)
ResponseFunction = void Function({DioError? dioError, Exception? exception, Response? response})
TxIdHex = String
Hex encoded transaction hash ID
UnusedAddressFunction = bool Function(ShelleyAddress address)
Function used to test address usage. Returns true if it has not been used in a transaction.
WalletId = String
Wallet ID - stakingPublicKey for Shelley wallets

Exceptions / Errors

CborDeserializationException
These classes define the data stored on the Cardano blockchain as defined by the shelley.cddl specification.
InvalidAddressTypeError