SDK Reference
Note: The SDK is still in beta and subject to change
SwayeClient Class
Represents a client for interacting with various blockchain APIs. This class provides access to a range of blockchain-related operations including blocks, ERC20 and ERC721 tokens, transactions, user management, chain information, and smart contract interactions.
Properties
block: BlockApi
Handles operations related to blockchain blocks. Provides methods to query and manipulate block data.erc20: ERC20Api
Manages ERC20 token related operations. Allows for interaction with ERC20 standard tokens, including transfers and balance queries.transaction: TransactionApi
Manages blockchain transaction operations. Enables the creation, submission, and tracking of transactions on the blockchain.user: UserApi
Manages user-related operations in the blockchain context. This can include user account information and activities on the blockchain.erc721: ERC721Api
Handles operations related to ERC721 tokens. Facilitates interaction with NFTs (Non-Fungible Tokens) adhering to the ERC721 standard.chain: ChainApi
Manages operations related to blockchain chains. Provides functionalities like querying chain status and properties.contract: ContractApi
Manages smart contract related operations. Allows for deploying, interacting with, and querying smart contracts on the blockchain.
Constructor
constructor(baseUrl: string, bearerToken?: string)
Constructs a newSwayeClient
instance.baseUrl: string
- The base URL for the API client.bearerToken?: string
- Optional. The bearer token for authentication. If provided, it is used to set the authorization header for HTTP requests.
Methods
setBearerToken(bearerToken: string): void
Sets or updates the bearer token for authentication with the blockchain services.bearerToken: string
- The new bearer token to be used for subsequent requests.
Usage
The SwayeClient
class is instantiated with the base URL of the blockchain service and an optional bearer token. Once created, it provides properties to access various aspects of the blockchain such as blocks, transactions, tokens, and smart contracts.
BlockApi Class
Handles API calls related to blockchain blocks.
Methods
getBlock(blockNumber: number | string): Promise<Block>
Fetches a block by its number or hash.blockNumber: number | string
- The block number or hash as a number or string.Returns: A promise that resolves to the
Block
object.Throws: An error if the API call fails.
getBlockNumber(): Promise<number | undefined>
Fetches the current block number.Returns: A promise that resolves to the current block number.
Throws: An error if the API call fails.
Usage
The BlockApi
class is used to interact with the blockchain block-related functionalities.
ChainApi Class
Handles API calls related to blockchain chain data. This class is responsible for fetching information specific to the blockchain network, such as its chain ID.
Methods
getChainId(): Promise<number>
Retrieves the unique identifier (ID) of the blockchain network.Returns: A promise that resolves to the chain ID as a number.
Throws: An error if the API call fails.
Usage
The ChainApi
class is used to interact with chain-related data of the blockchain. It requires an instance of ApiClient
to make API requests.
ContractApi Class
Responsible for handling API calls related to smart contracts on the blockchain. This class provides functionalities for interacting with smart contracts, including calling contract functions.
Methods
callContract(data: CallContractRequest): Promise<string>
Calls a function on a smart contract.CallContractRequest
Interface representing a request to call a contract function.
functionSignature: string
- The signature of the contract function to be called.params: string[]
- An array of parameters for the contract function.contractAddress: string
- The address of the smart contract on the blockchain.
Returns: A promise that resolves to the response from the contract call as a string.
Throws: An error if the API call fails.
Usage
ERC20Api Class
Handles API calls related to ERC20 tokens. This class provides functionalities for various ERC20 token operations, such as querying balances, initiating transfers, and managing allowances.
Methods
getBalance(request: ERC20BalanceRequest): Promise<string>
Retrieves the balance of an ERC20 token for a given address.ERC20BalanceRequest
Interface for ERC20 balance request.
address: string
- The address whose token balance is being queried.contractAddress: string
- The contract address of the ERC20 token.
Parameters
request: ERC20BalanceRequest
- The request data.
Returns: A promise that resolves to the token balance as a string.
Throws: An error if the API call fails.
Usage:
transfer(request: ERC20TransferRequest): Promise<string>
Initiates a transfer of ERC20 tokens.ERC20TransferRequest
Interface for ERC20 transfer request.
address: string
- The address initiating the transfer.amount: string
- The amount of tokens to transfer.contractAddress: string
- The contract address of the ERC20 token.
Parameters
request: ERC20TransferRequest
- The request data.
Returns: A promise that resolves to the transaction result as a string.
Throws: An error if the API call fails.
Usage:
approve(request: ERC20ApproveRequest): Promise<string>
Approves a spender to withdraw from your account, multiple times, up to the specified amount.ERC20ApproveRequest
Interface for ERC20 approve request.
address: string
- The address granting the approval.amount: string
- The maximum amount the spender can withdraw.contractAddress: string
- The contract address of the ERC20 token.
Parameters
request: ERC20ApproveRequest
- The request data.
Returns: A promise that resolves to the approval result as a string.
Throws: An error if the API call fails.
Usage:
transferFrom(request: ERC20TransferFromRequest): Promise<string>
Transfers tokens from one address to another.ERC20TransferFromRequest
Interface for ERC20 transferFrom request.
contractAddress: string
- The contract address of the ERC20 token.from: string
- The address from which the tokens are withdrawn.to: string
- The address to which the tokens are sent.amount: string
- The amount of tokens to transfer.
Parameters
request: ERC20TransferFromRequest
- The request data.
Returns: A promise that resolves to the transaction result as a string.
Throws: An error if the API call fails.
Usage:
allowance(request: ERC20AllowanceRequest): Promise<string>
Retrieves the amount which a spender is still allowed to withdraw from an owner.ERC20AllowanceRequest
Interface for ERC20 allowance request.
owner: string
- The address of the token owner.spender: string
- The address of the spender.contractAddress: string
- The contract address of the ERC20 token.
Parameters
request: ERC20AllowanceRequest
- The request data.
Returns: A promise that resolves to the allowance amount as a string.
Throws: An error if the API call fails.
Usage:
totalSupply(request: ERC20TotalSupplyRequest): Promise<string>
Gets the total token supply.ERC20TotalSupplyRequest
Interface for ERC20 total supply request.
contractAddress: string
- The contract address of the ERC20 token.
Parameters
request: ERC20TotalSupplyRequest
- The request data.
Returns: A promise that resolves to the total token supply as a string.
Throws: An error if the API call fails
Usage:
ERC721Api Class
Handles API calls for ERC721 token operations.
Methods
getBalance(request: ERC721BalanceRequest): Promise<string>
Gets the balance of ERC721 tokens for a given address.
Parameters:
Interface for ERC721 balance request
address: string
address to query balance ofcontractAddress: string
contract address of the ERC721 Token
request
: An object of typeERC721BalanceRequest
Returns: A promise that resolves to the token balance as a string.
Usage Example:
transfer(request: ERC721TransferRequest): Promise<string>
Initiates a transfer of ERC721 tokens.
Parameters:
Interface of ERC721 Transfer request
from: string
sender addressto: string
reciepent addresstokenId: string
ERC721 tokenIdcontractAddress: string
contract address of the ERC721 token.
request
: An object of typeERC721TransferRequest
Returns: A promise that resolves to the transaction result.
Usage Example:
approve(request: ERC721ApproveRequest): Promise<string>
Approves an address to transfer a specific token.
Parameters:
Interface
of ERC721 approve requestapprovedAddress: string
address to approvetokenId: string
ERC721 token IdcontractAddress: string
contract address of ERC721 Token
request
: An object of typeERC721ApproveRequest
Returns: A promise that resolves to the approval result.
Usage Example:
safeTransferFrom(request: ERC721TransferRequest): Promise<string>
Safely transfers ERC721 tokens.
Parameters:
request
: Same as intransfer
method.
Returns: A promise that resolves to the transaction result.
Usage Example:
approved(request: ERC721ApprovedRequest): Promise<string>
Retrieves the approved address for a specific token.
Parameters:
Interface of ERC721 Approved request
tokenId: string
token Id of ERC721contractAddress: string
contract address of ERC721 Token
request
: An object of typeERC721ApprovedRequest
Returns: A promise that resolves to the approved address.
Usage Example:
setApprovalForAll(request: ERC721SetApprovalForAllRequest): Promise<string>
Sets or unsets the approval of an operator.
Parameters:
Interface of Set approval for all request
operator: string
address to give approval toapproved: boolean
true to give approval, false to revokecontractAddress: string
contract address of the ERC721 token
request
: An object of typeERC721SetApprovalForAllRequest
containingoperator
,approved
, andcontractAddress
.
Returns: A promise that resolves to the transaction result.
Usage Example:
isApprovedForAll(request: ERC721IsApprovedForAllRequest): Promise<string>
Checks if an operator is approved to manage all tokens of an owner.
Parameters:
Interface of Is approved for all request
owner: string
owner addressoperator: string
operator addresscontractAddress: string
contract address of ERC721 Token
request
: An object of typeERC721IsApprovedForAllRequest
Returns: A promise that resolves to a boolean indicating approval status.
Usage Example:
getTokenOfOwnerByIndex(request: ECR721GetTokenOfOwnerByIndexRequest): Promise<string>
Gets the tokenId at a given index of tokens owned by an address.
Parameters:
Interface of Get token of owner by index request
address: string
owner addressindex: number
index of token to get Id ofcontractAddress: string
contract address of ERC721 Token
request
: An object of typeECR721GetTokenOfOwnerByIndexRequest
Returns: A promise that resolves to the tokenId.
Usage Example:
getAllTokensOfOwner(request: ERC721GetAllTokensOfOwnerRequest): Promise<string[]>
Gets all tokenIds of tokens owned by an address.
Parameters:
Interface of Get all tokens of owner request
address: string
owner addresscontractAddress: string
contract address of ERC721 Token
request
: An object of typeERC721GetAllTokensOfOwnerRequest
Returns: A promise that resolves to an array of tokenIds.
Usage Example:
getTokenURI(request: ECR721GetTokenURI): Promise<string>
Gets the URI of an ERC721 token.
Parameters:
Interface of Get Token URI
tokenId: string
ERC721 token IdcontractAddress: string
contract address of ERC721 Token
request
: An object of typeECR721GetTokenURI
containingtokenId
andcontractAddress
.
Returns: A promise that resolves to the token URI.
Usage Example:
TransactionApi Class
Handles API calls for blockchain transaction operations.
Methods
submitTransactionRequest(transactionRequest: TransactionRequest): Promise<TransactionResponse>
Submits a transaction request to the blockchain.
Parameters:
transactionRequest
: An object of typeTransactionRequest
containing details of the transaction such asfunctionSignature
,params
,contractAddress
, and optionallyvalue
.
Returns: A promise that resolves to a
TransactionResponse
object.Usage Example:
getTransaction(hash: string): Promise<Transaction>
Retrieves a transaction by its hash.
Parameters:
hash
: The hash of the transaction to be retrieved.
Returns: A promise that resolves to a
Transaction
object.Usage Example:
getTransactionReceipt(hash: string): Promise<TransactionReceipt>
Retrieves the receipt of a transaction by its hash.
Parameters:
hash
: The hash of the transaction for which the receipt is to be retrieved.
Returns: A promise that resolves to a
TransactionReceipt
object.Usage Example:
Based on the TypeScript class provided, here's the reference documentation for the UserApi
class, which handles API calls related to user information and accounts. Each function's description includes its purpose, input parameters, return type, and a usage example.
UserApi Class
Handles API calls for user information and account operations.
Methods
getUser(): Promise<User>
Retrieves the details of the current user.
Returns: A promise that resolves to a
User
object.Usage Example:
getBalance(): Promise<string>
Retrieves the balance of the current user.
Returns: A promise that resolves to the balance as a string.
Usage Example:
getAccounts(): Promise<string[]>
Retrieves the accounts associated with the current user.
Returns: A promise that resolves to an array of account strings.
Usage Example:
Last updated