Solen Library

Context Object

class solen.context.Context(env: Optional[str] = None)[source]

Context class.

Parameters

env – The Solana env (options are based on the config file)

The Solana RPC endpoint is taken from the config file - based on the given env parameter. For example, using the config file: in the example and “dev” parameter, the RPC endpoint will be:https://api.devnet.solana.com

>>> from solen import Context
>>> context = Context("dev")
init(env: str)[source]

Init Solen instance based on env parameter.

NFT Client

class solen.nft_client.NFTClient(env: str, context: Optional[solen.context.Context] = None)[source]

NFT Client class.

Parameters

env – The Solana env (options are based on the config file)

The Solana RPC endpoint is taken from the config file - based on the given env parameter. For example, using the config file in the example and “dev” parameter, the RPC endpoint will be:https://api.devnet.solana.com

bulk_confirm_transactions(csv_path: str)[source]

Verify that update transaction signatures are finalized.

Parameters

csv_path – Path to the csv file that been processed.

bulk_get_data(mint_key_list: List[str], sort_creators_by_share: bool = True) List[Dict][source]

Bulk call to get_data function, to get the NFT On-Chain data of nfts in the input list.

Parameters
  • mint_key_list – mint address list to query

  • sort_creators_by_share – If true the creators, verified and share lists will be sorted correspondingly by the share amount - the highest first (default: true).

>>> from solen import NFTClient
>>> nft_client = NFTClient("main")
>>> metadata = nft_client.nft.bulk_get_data(["DAysz5tmEMQBhXgcQHXrhQaF3rGwVw3LKoj5vMHY9vxM",
>>>                                          "7Sde2VNGTcHv5wmgrYTvGW9h8Umiob5MdTq6Y7BuTw7h"])
bulk_sum_info(in_process: Optional[Dict] = None, log_sum: bool = False)[source]

Log sum status for

Parameters
  • in_process – Current content of the in-process json file (default taken from bulk_update_nft_handler).

  • log_sum – If true the sum data will be logged (not just returned).

bulk_update_init(csv_path: str)[source]

Create the bulk update config based on given CSV file.

Parameters

csv_path – Path to a csv file in the format of: wallet,amount.

bulk_update_nft(csv_path: str, dry_run=False, skip_confirm=False)[source]

Update multiple NFTs, based on the content of transfer_csv_path.

Parameters
  • csv_path – Path to a csv file in the format of: mint_address,VALUE_TO_UPDATE. Options for value to update: symbol, name, uri

  • dry_run – When true the transactions will be skipped.

  • skip_confirm – When true transaction confirmation will be skipped. Run will be faster but less reliable.

>>> from solen import NFTClient
>>> token_client = NFTClient("dev")
>>> token_client.bulk_update_nft(csv_path)
when csv should contain update actions data, for example:
mint_address,symbol
Cy4y1XGR9pj7vFikWVGrdQAPWCChqV9gQHCLht6eXBLW,MQA
Cy4y1XGR9pj7vFikWVGrdQAPWCChqV9gQHCLht6eXBLW,MQA
get_all_nft_accounts_by_owner(owner: Optional[Union[solana.publickey.PublicKey, str]] = None) List[source]

Get all NFT accounts owned by the given owner.

Parameters

owner – The owner address to query for NFTs.

get_current_holder(mint_address: str) str[source]

get current holder owners for a given NFT.

Parameters

mint_address – mint address to query.

>>> from solen import NFTClient
>>> nft_client = NFTClient("main")
>>> nft_client.get_current_holder("7Sde2VNGTcHv5wmgrYTvGW9h8Umiob5MdTq6Y7BuTw7h")
    'FPqcXeEAt3WtRD8QcSVRcX9WD1zuM5xxvJQhfE9XJbLF'
get_data(mint_key: str, sort_creators_by_share: bool = True) Dict[source]

Get the NFT On-Chain data. The creators data returned sorted by share.

param mint_key

The NFT mint address.

param sort_creators_by_share

If true the creators, verified and share lists will be sorted correspondingly by the share amount - the highest first (default: true).

>>> from solen import NFTClient
>>> nft_client = NFTClient("main")
>>> metadata = nft_client.get_data("DAysz5tmEMQBhXgcQHXrhQaF3rGwVw3LKoj5vMHY9vxM")
>>> print(json.dumps(metadata, indent=4))  
{"update_authority": "AuoD4FKLSDKpuNm7y1G5RX3jBdrXerHfaVjfP415miET",
 "mint": "DAysz5tmEMQBhXgcQHXrhQaF3rGwVw3LKoj5vMHY9vxM",
 "data": {
     "name": "Monkey #3882",
     "symbol": "ML",
     "uri": "https://arweave.net/q54T5RnKno8h8W_PtVL9xUQXh6tPZw4eTAxphS1Og38",
     "seller_fee_basis_points": 450,
     "creators": [
         "BAjb6D4n8LGrzGpncShKFxkD8dpGKM3KoZ6yrmSrai8k",
         "AuoD4FKLSDKpuNm7y1G5RX3jBdrXerHfaVjfP415miET",
         "3xiSExYoVT63E8bMQpF4FAYfXSGU9CMm5E5zBz1cDKGb"
     ],
     "verified": [0, 0, 1],
     "share": [100, 0, 0]
 },
 "primary_sale_happened": true,
 "is_mutable": true}
>>> print(metadata.data.name) 
Monkey #3882
get_historical_holders_associate_accounts(mint_address: str)[source]

get all historical holders accounts for a given NFT. The function returna the associated accounts and not the owners accounts. To get the owners need to use get_historical_holders_owners.

Parameters

mint_address – mint address to query.

get_holders(mint_address: str)[source]

get all historical holders owners for a given NFT.

Parameters

mint_address – mint address to query.

>>> from solen import NFTClient
>>> nft_client = NFTClient("main")
>>> nft_client.get_holders("7Sde2VNGTcHv5wmgrYTvGW9h8Umiob5MdTq6Y7BuTw7h")
    ['FPqcXeEAt3WtRD8QcSVRcX9WD1zuM5xxvJQhfE9XJbLF',
    'AuoD4FKLSDKpuNm7y1G5RX3jBdrXerHfaVjfP415miET']
get_owner_of_associate_account(associated_address: str)[source]

get the owner of a given associated account.

Parameters

associated_address – associated address to query.

get_transaction_data(signatures: str) Dict[source]

get transaction data.

Parameters

signatures – transaction signatures.

get_transactions(mint_address: str) List[Dict][source]

get historical transactions for a given NFT.

Parameters

mint_address – mint address to query.

>>> from solen import NFTClient
>>> nft_client = NFTClient("main")
>>> transactions = nft_client.get_transactions("9DAhGeEUYboU4EvGNvgPajZ6Acd9UfDX9aB5zGv6oTJj")
[{'blockTime': 1641486108,
  'confirmationStatus': 'finalized',
  'err': None,
  'memo': None,
  'signature': '3H2SvadvjjwwWoCjmhC68sqVVJK79oXkzokfPMscNvX5RYatzVPceLSzTEztujSXZPf5FSySaYVe4oigkyNG88e2',
  'slot': 115072701,
  'time': datetime.datetime(2022, 1, 6, 18, 21, 48)},...]
>>> transactions[0].signature
    '3H2SvadvjjwwWoCjmhC68sqVVJK79oXkzokfPMscNvX5RYatzVPceLSzTEztujSXZPf5FSySaYVe4oigkyNG88e2'
get_update_status(csv_path: str)[source]

Get update status for a given update csv file.

Parameters

csv_path – Path to a csv file to retrieve update data for.

update_token_metadata(mint_address, max_retries=1, skip_confirmation=False, max_timeout=60, target=20, finalized=True, dry_run=False, **kwargs) Dict[source]

Updates the metadata for a given NFT.

Parameters
  • mint_address – The NFT mint address.

  • max_retries – Mac retry attempts of send_transaction in case of failure.

  • skip_confirmation – If true send transfer will not be coffirmed. It might be faster.

  • max_timeout – Max timeout for transaction confirmation. Not used if skip_confirmation is True.

  • target – Target for confirmations transaction confirmation. Not used if skip_confirmation is True.

  • finalized – If true transaction confirmed only if it has status Finalized, else target is used to confirm transaction.

  • dry_run – If true the transfer will not be executed.

  • kwargs – The data that need to be changed. Options are: uri, name, symbol, fee, creators

  • uri : str

  • name : str

  • symbol : str

  • fee : int (precentage as int. instead of 4.5% it should be 450)

  • creators : list of dicts. each dict must contain:

    • address : str - the creator address

    • verified : int - 0 or 1

    • share : int - between 0 and 100 (for royalty share between creators)

>>> from solen import NFTClient
>>> nft_client = NFTClient("dev")
>>> response = nft_client.update_token_metadata("CF4wMo1YnK44BL8R8ZpEUpY4iskWX5KAHbRXMUvpqnJL",
>>>                                             name="Monkey 6001")

In case os an error, the signature will be in response.err, In case os succefull update, the signature will be in response.ok.

Token Client

class solen.token_client.TokenClient(env: str, token_mint: Optional[str] = None, context: Optional[solen.context.Context] = None)[source]

Token Client class.

Parameters
  • env – The Solana env (options are based on the config file)

  • token_mint – The token mint address, token commands will be based on that token. (default taken from the config file)

The Solana RPC endpoint is taken from the config file - based on the given env parameter. For example, using the config file: in the example and “dev” parameter, the RPC endpoint will be: https://api.devnet.solana.com

balance(owner: Optional[Union[solana.publickey.PublicKey, str]] = None) int[source]

Returns the token balance for the given dest address. (default is keypair address)

Parameters

owner – The address that need to query for token balance (default is configured keypair address).

>>> from solen import TokenClient
>>> token_client = TokenClient("dev")
>>> token_client.balance()
bulk_confirm_transactions(csv_path: str)[source]

Verify that transfer amount transaction signatures are finalized.

Parameters

csv_path – Path to the csv file that been processed.

bulk_sum_info(in_process: Optional[Dict] = None, log_sum: bool = False)[source]

Log sum status for token transfer

Parameters
  • in_process – Current content of the in-process json file (default taken from bulk_transfer_token_handler).

  • log_sum – If true the sum data will be logged (not just returned).

bulk_transfer_token(csv_path: str, dry_run=False, skip_confirm=False)[source]

Transfer token to multiple addresses, based on the content of transfer_csv_path.

Parameters
  • csv_path – Path to a csv file in the format of: dest,amount.

  • dry_run – When true the transactions will be skipped.

  • skip_confirm – When true transaction confirmation will be skipped. Run will be faster but less reliable.

>>> from solen import TokenClient
>>> token_client = TokenClient("main")
>>> token_client.bulk_transfer_token(csv_path)
when csv should contain transfer actions data, for example:
dest,amount
Cy4y1XGR9pj7vFikWVGrdQAPWCChqV9gQHCLht6eXBLW,0.001
Cy4y1XGR9pj7vFikWVGrdQAPWCChqV9gQHCLht6eXBLW,0.001
bulk_transfer_token_init(csv_path: str)[source]

Create the bulk transfer config based on given CSV file.

Parameters

csv_path – Path to a csv file in the format of: dest,amount.

create_associated_token_account(owner: str) solen.response.Response[source]

Create an associated token account

Parameters

owner – The address that need to create a token associated address for.

get_associated_address(owner: str, token: Optional[str] = None) solana.publickey.PublicKey[source]

Derives the associated token address for the given dest address and token mint.

Parameters
  • owner – The owner address that need to query for token associated address.

  • token – The token need to query for associated address in the given address (default: configured token).

get_registered_info(**kwargs) List[Dict][source]

return Solana registered token info.

Parameters

kwargs – filter param - can get only one filter option from the following: [address, symbol, name, tags] (Default is address of configured token).

>>> from solen import TokenClient
>>> token_client = TokenClient("main")
>>> token_client.get_registered_info(symbol="TINY")
get_token_decimals(pubkey: Optional[Union[solana.publickey.PublicKey, str]] = None) int[source]

Returns the decimal config of an SPL Token type. (default is the configured token)

Parameters

pubkey – The token mint address we want to get decimal info for (default is configured token).

>>> from solen import TokenClient
>>> token_client = TokenClient("dev")
>>> token_client.get_token_decimals()
get_transfer_status(csv_path: str)[source]

Get transfer status for a given transfer csv file.

Parameters

csv_path – Path to a csv file to retrieve transfer data for.

is_account_funded(address: str) bool[source]

Return true id the given account exist and founded.

Parameters

address – The address to query.

is_it_token_account(address: str) bool[source]

Returns true if the given address is a token associate account.

Parameters

address – The address to query.

transfer_token(dest: str, amount: float, dry_run: bool = False, skip_confirmation: bool = False, commitment: Commitment = 'confirmed') Dict[source]

Generate an instruction that transfers amount of configured token from one self account to another.

Parameters
  • dest – Recipient address.

  • amount – Amountof token to transfer.

  • dry_run – If true the transfer will not be executed.

  • skip_confirmation – If true send transfer will not be coffirmed. It might be faster.

  • commitment – The commitment type for send transfer.

>>> from solen import TokenClient
>>> from solana.rpc.commitment import Processed
>>> token_client = TokenClient("dev")
>>> token_client.transfer_token("Cy4y1XGR9pj7vFikWVGrdQAPWCChqV9gQHCLht6eXBLW", 0.01, True, Processed)

SOL Client

class solen.sol_client.SOLClient(env: str, context: Optional[solen.context.Context] = None)[source]

SOL client class.

Parameters

env – The Solana env (options are based on the config file)

The Solana RPC endpoint is taken from the config file - based on the given env parameter. For example, using the config file: in the example and “dev” parameter, the RPC endpoint will be: https://api.devnet.solana.com

balance(owner: Optional[str] = None) int[source]

Returns the SOL amount for the given wallet address

>>> from solen import SOLClient
>>> sol_client = SOLClient("main")
>>> sol_client.balance()