worken_sdk 2.0.0
worken_sdk: ^2.0.0 copied to clipboard
SDK library providing access to make easy and secure transactions with Worken.
Send & Receive secure Blockchain transactions on Solana with Worken
🚀 Over 20M+ Users using Worken!
SDK library providing access to make easy and secure Blockchain transactions with Worken. Read more about Worken Token.
Configuration #
To ensure flexibility and ease of integration, the Worken SDK allows for configuration through environmental variables. These variables can be set directly in your project's .env file. Below is a list of available configuration variables along with their descriptions:
To get more information about those below, please read it
rpcUrl
: rpcUrl
websocketUrl
: websocketUrl
Usage #
Install
$ flutter pub add worken-sdk
Initialization
import 'package:worken_sdk/worken_sdk.dart';
import 'package:solana/solana.dart';
import 'package:get_it/get_it.dart';
/// Setup even if don't want to use your paths
await WorkenSdk.setup(
typeNet: typeNet
provider: SolanaClient(rpcUrl, websocketUrl),
locator: GetIt.instance, // your locator
);
Parameter | Type | Description |
---|---|---|
typeNet |
SolanaNet |
if provider is null, please set typeNet (mainNet, devNet, testNet) |
provider |
SolanaClient |
if want to use yours client |
locator |
GetIt |
if want to use yours locator |
Wallet #
WorkenSdk.getWalletService(); /// Service to extract functions
also, if setup with locator
locator.get<WalletService>(); /// Get service from locator
Get wallet balance
WorkenSdk.getWalletService().getBalance(address: address);
Parameter | Type | Description |
---|---|---|
address |
String |
Required Your wallet address |
This structure details the balance of a wallet in terms of the WORK token specified in contract It returns TokenAmount model which contains data like:
amount
: asString
- raw amount of tokens as astring
, ignoring decimalsdecimals
: asint
- number of decimals configured for token's mintuiAmountString
: asString?
- token amount as a string, accounting for decimals
Get wallet transaction history
WorkenSdk.getWalletService().getTransactions(address: address);
Parameter | Type | Description |
---|---|---|
address |
String |
Required Your wallet address |
This method returns list of TransactionSignatureInformation
that contains data like:
signature
: asString
- transaction signature asbase-58 encoded string
slot
: asint
- the slot that contains the block with the transactionerr
: asMap<String, dynamic>?
- contains error detailsmemo
: asString?
- memo associated with the transaction,null
if no nemo is presentblockTime
: asint?
- estimated production time, asUnix timestamp
of when transaction was processed.Null
if not availableconfirmationStatus
: asConfirmationStatus?
- the transaction's cluster confirmation status
Create new wallet
WorkenSdk.getWalletService().createWallet();
Creates and initializes the account SolanaWallet and the change account for the given bip39 mnemonic string of 12 words
.
Omitting account or change means they will be null
with the following rules of the meaning of null in this context.
If either account or change is null, and the other is not, then it will be taken to be zero
.
Contract #
WorkenSdk.getContractService(); /// Service to extract functions
also, if setup with locator
locator.get<ContractService>(); /// Get service from locator
Show contract status
WorkenSdk.getContractService().getContractStatus();
This method returns all information associated with the account of provided Pubkey
lamports
: asint
- number of lamports assigned to this account, as a u64owner
: asString
- base-58 encoded Pubkey of the program this account has been assigned todata
: asAccountData?
- data associated with the account, either as encoded binary data or JSON formatexecutable
: asbool
- boolean indicating if the account contains a programrentEpoch
: asBigInt
- the epoch at which this account will next owe rent, as u64
Transactions #
WorkenSdk.getTransactionService(); /// Service to extract functions
also, if setup with locator
locator.get<TransactionsService>(); /// Get service from locator
Prepare transaction #
WorkenSdk.getTransactionService().prepareTransaction({
required String sourcePrivateKey,
required String sourceWallet,
required String destinationWallet,
required int amount});
Parameter | Type | Description |
---|---|---|
sourcePrivateKey |
String |
Required. Sender private key in base58 |
sourceWallet |
String |
Required. Receiver wallet address |
destinationWallet |
String |
Required. Mint address |
amount |
int |
Required. Amount to send in WORKEN |
This function prepares transaction in Worken SPL token
It returns us txHash String
Send transaction
WorkenSdk.getTransactionService().sendTransaction();
Parameter | Type | Description |
---|---|---|
hashString |
String |
Required. prepared txHash |
This function sends prepared transaction
It returns us signature hash String
Show transaction status
WorkenSdk.getTransactionService().transactionStatus({required String signature});
Parameter | Type | Description |
---|---|---|
signature |
String |
Required. Signature string of transaction |
This function shows us the status of desired transaction we want to check. It returns us SignatureStatusesResult which contains data like:
slot
: asint
- the slot the transaction was processedconfirmations
: asConfirmationStatus
- the transaction's cluster confirmation statusconfirmationStatus
: asint?
- number of block since signature confirmation,null
if rooted, as well as finalizederr
: asMap<String, dynamic>
- error message
Get estimated fee #
WorkenSdk.getTransactionService().estimatedFee({required String message});
Parameter | Type | Description |
---|---|---|
message |
String |
Required. Typically message is our hashKey |
This function returns us int?
- estimated Fee we will have to pay
Show recent transactions
WorkenSdk.getTransactionService().recentTransactions({required String mintAddress, required int limit});
Parameter | Type | Description |
---|---|---|
mintAddress |
String |
Required. Your mint address |
limit |
int |
Required. Amount of transactions we want to see |
This function returns us List<TransactionSignatureInformation>
which contains data like:
signature
: asString
- transaction signature as base-58 encoded stringslot
: asint
- the slot that contains the block with the transactionerr
: asMap<String, dynamic>
- error messagememo
: asString?
- memo associated with the transaction,null
if no memo is presentblockTime
: asint?
- estimated production time, asUnix timestamp
of when transaction was processed.null
if not availableconfirmationStatus
: asConfirmationStatus?
- the transaction's cluster confirmation status
Network #
WorkenSdk.getNetworkService(); /// Service to extract functions
also, if setup with locator
locator.get<NetworkService>(); /// Get service from locator
Show block information
WorkenSdk.getNetworkService().blockInformation(blockNumber: blockNumber);
Parameter | Type | Description |
---|---|---|
blockNumber |
int |
Required. Number of block |
This function retrieves detailed information about a specific block on the blockchain.
It returns Block
model which contains data like:
blockhash
: asString
- the blockhash of this block, as base-58 encoded stringpreviousBlockhash
: asString
- the blockhash of this block's parent, as base-58 encoded string. If the parent block is not available due to ledger cleanup, this field will return1111..11
parentSlot
: asint
- the slot index of this block's parenttransactions
: asList<Transaction>
- present ifTransactionDetailLevel.full
transaction details are requested. An array ofTransaction
objectsmeta
: asMeta?
- transaction status metadata objectsignatures
: asList<String>
- present ifTransactionDetailLevel.signatures
are requested for transaction details. An array of signaturesstrings
, corresponding to the transaction order in the blockrewards
: asList<Reward>
- present if rewards are requested. An array ofReward
objectsblockTime
: asint?
- estimated production time, asUnix timestamp
.None
if not availableblockHeight
: asint?
- the number of blocks beneath this block
Show network status
WorkenSdk.getNetworkService().networkStatus();
This function returns a NetworkStatusModel:
blockData
: asint
- the current block height of the nodefeeRate
asint?
- the fee the network will charge for a particular Message
Show monitor network congestion
WorkenSdk.getNetworkService().monitorCongestion();
This function returns a list of PerfSample:
slot
: asint
- slot in which sample was taken atnumTransactions
: asint
- number of transactions in samplenumSlots
: asint
- number of slots in samplesamplePeriodSecs
: asint
- number of seconds in a sample window