Solana Provider
You can interact with Solana blockchains using @solana/web3.js together with the Wepin Provider.
Supported Networks
Chain ID | Network Name | Network Variable |
---|---|---|
solana:mainnet | Solana Mainnet | solana |
solana:devnet | Solana Devnet | solana-devnet |
Installation
Once the installation is complete, initialize the WepinProvider instance using the app ID and app key assigned after registering the app. This will enable the use of WepinProvider.
Initialization
Here's how to initialize the Wepin Provider.
init
Parameters
attributes
<object> optionaldefaultLanguage
: The language to be displayed on the widget (default:'ko'
) Currently, only'ko'
,'en'
and'ja'
are supported.defaultCurrency
: The currency to be displayed on the widget (default:'KRW'
) Currently, only'KRW'
,'USD'
and'JPY'
are supported.
Return value
Promise
<void>
Example
isInitialized
It checks if WepinProvider is initialized properly.
Parameters
<void>
Return value
<boolean>
Returnstrue
if init was successful, otherwise returnsfalse
.
Example
changeLanguage
It allows changing the language and currency of the widget.
Parameters
attributes
<object>language
<string> It specifies the language to be displayed on the widget. Currently supported languages areen
,ko
andja
currency
<string> It specifies the currency to be displayed on the widget. Currently supported currencies areUSD
,KRW
andJPY
Return value
<boolean> It returns
true
if the change was successful, otherwise returnsfalse
.
Example
Methods
Methods can be used after initializing the Wepin Provider.
getProvider
It returns the provider for the specified network.
Parameters
network
<string> The Network Variable value for providers supported by Wepin, such as "solana" for Solana Mainnet, must be entered in lowercase. For the complete list, please refer to the Supported Networks for Solana Provider.
Return value
Promise
<BaseProvider> - A solana provider
Example
finalize
It terminates the use of WepinProvider.
Parameters
<void>
Return value
<void>
Example
request
You can send JSON-RPC requests to interact with the Solana blockchain.
connect
Connects to the Wepin Wallet and requests permission to share the user's account address (Public Key). Once the connection is approved, the application can make further requests, such as signing messages or transactions.
Parameters
<void>
Return value
Promise
<object>publicKey
<string> - Solana Account's Address(Public Key)
Example
signTransaction
Signs a serialized transaction. Takes the transaction as a hex string and returns the signed transaction.
Parameters
<object>
message
<string> - A transaction serialized and converted to a hex string.
Return value
Promise
<Transaction> - A Transaction that includes a signature.
Example
signAndSendTransaction
Signs and submits the serialized transaction to the Solana network. Returns the signature of the transaction.
Parameters
<object>
message
<string> - A transaction serialized and converted to a hex string.
Return value
Promise
<object>signature
<TransactionSignature> - The signature of the Transaction.
Example
signMessage
Signs a message with a specified account's address (Public Key). Takes the account address and the message to be signed as input.
Parameters
<array>
<string>
- The address (Public Key) of the account that signs the transaction.<string>
- The message to be signed.
Return value
Promise
<Transaction> - A Transaction that includes a signature.
Example
changeNetwork
Switches the network. Supports switching between Solana Mainnet and Devnet, and returns the address, network name, and chain ID of the switched network.
Parameters
<object>
chainId
<string> - The chainId of the network to switch to. Only Solana chains (solana , solana ) are supported.
Return value
Promise
<object>address
<string> - The account address (Public Key) on the switched network.network
<string> - The name of the switched network.chainId
<string> - The chain ID of the switched network.
Example
Other Method Example
In addition to the methods provided by Wepin, Solana RPC HTTP methods are also available.
Returns all information associated with the account of provided Pubkey
Parameters
PubKey
<string> - Address of the account to retrieve (encoded in base-58).<object>
commitment
<string> optionalDefault Commitment - finalize
processed - Fetches the latest block processed by the node, which is not yet finalized and may change.
confirmed - Fetches the latest block approved by a majority in the cluster.
finalized - Fetches the latest block finalized by a majority in the cluster.
encoding
<string> optionalEncoding format for account data.
base58, base64, base64+zstd, jsonParsed
dataSlice
<object> optional - Request a slice of the account's data. Used only withbase58
,base64
, orbase64+zstd
encoding.length
<usize> - Number of bytes to return.offset
<usize> - Byte offset to start reading from.
minContextSlot
<number> optionalMinimum slot for executing the request.
Return value
context
<object>apiVersion
<string> - solana-core versionslot
<number> - Slot at which the operation was executed.
value
<object> nullablelamports
<u64> - Account balance in lamports.owner
<string> - Address of the program managing this account (encoded in base-58).data
<[string, encoding] | object> - Data associated with the account.executable
<boolean> - Boolean indicating if the account contains a program (read-only).rentEpoch
<u64> - the epoch at which this account will next owe rent, as u64size
<u64> - Size of the account data.
Example
Returns the lamport balance of the account of provided Pubkey.
Parameters
Pubkey
<string> - Address of the account to check balance (encoded in base-58).<object>
commitment
<string> optionalDefault Commitment - finalize
processed - Fetches the latest block processed by the node, which is not yet finalized and may change.
confirmed - Fetches the latest block approved by a majority in the cluster.
finalized - Fetches the latest block finalized by a majority in the cluster.
minContextSlot
<number> optionalMinimum slot for executing the request.
Return value
context
<object>apiVersion
<string> - solana-core versionslot
<number> - Slot at which the operation was executed.
value
<number> - Account balance.
Example
Returns the latest blockhash.
Parameters
<object> optional
commitment
<string> optionalDefault Commitment - finalize
processed - Fetches the latest block processed by the node, which is not yet finalized and may change.
confirmed - Fetches the latest block approved by a majority in the cluster.
finalized - Fetches the latest block finalized by a majority in the cluster.
minContextSlot
<number> optionalMinimum slot for executing the request.
Return value
context
<object>apiVersion
<string> - solana-core versionslot
<number> - Slot at which the operation was executed.
value
<object>blockhash
<string> - a Hash as base-58 encoded stringlastValidBlockHeight
<number> - last block height at which the blockhash will be valid
Example
Returns all SPL Token accounts by token owner.
Parameters
PubKey
<string> - the account address (Pubkey as base-58 encoded string)<object> - Filter for SPL Token accounts to query; requires either
mint
orprogramId
.mint
<string> - Address of a specific token’s Mint (encoded in base-58).programId
<string> - ID of a specific program (encoded in base-58).
<object>
commitment
<string> optionalDefault Commitment - finalize
processed - Fetches the latest block processed by the node, which is not yet finalized and may change.
confirmed - Fetches the latest block approved by a majority in the cluster.
finalized - Fetches the latest block finalized by a majority in the cluster.
minContextSlot
<number> optionalMinimum slot for executing the request.
encoding
<string> optionalEncoding format for account data.
base58, base64, base64+zstd, jsonParsed.
dataSlice
<object> optional - Used only withbase58
,base64
, orbase64+zstd
encoding.length
<usize> - Number of bytes to return.offset
<usize> - Byte offset to start reading from.
Return value
context
<object>apiVersion
<string> - solana-core version.slot
<number> - Slot at which the operation was executed.
value
<Array<object>> - Array of SPL Token account objects.pubkey
<string> - Address of the retrieved account.account
<object> - Account details.lamports
<u64> - Account balance in lamports.data
<object> - Token state data associated with the account.parsed
<object>info
<object> - Account information.isNative
<boolean> - Indicates if the account is native; usually false.mint
<string> - Address of the token’s mint associated with the account.owner
<string> - Owner of the token account.state
<string> - Token account status.tokenAmount
<object> - Token balance information.amount
<string> - Raw amount of tokens as a string, ignoring decimals.decimals
<number> - Number of decimals configured for token's mint.uiAmount
<number> - Token amount as a float, accounting for decimals. DEPRECATEDuiAmountString
<string> - Token amount as a string, accounting for decimals.
type
<string> - Type ofinfo
; usuallyaccount
.
program
<string> - Program to which the account belongs.space
<number> - Account data size in bytes.
executable
<boolean> - Indicates if the account is executable.owner
<string> - Program address that owns the account.rentEpoch
<u64> - the epoch at which this account will next owe rent, as u64size
<u64> - Data size of the account.
Example
Returns the token balance of an SPL Token account.
Parameters
PubKey
<string> - ATA(Associated Token Account) address (encoded in base-58).
Return value
context
<object>apiVersion
<string> - solana-core versionslot
<number> - Slot at which the operation was executed.
value
<object>amount
<string> - Raw amount of tokens as a string, ignoring decimals.decimals
<number> - Number of decimals configured for token's mint.uiAmount
<number> nullable - Token amount as a float, accounting for decimals. DEPRECATEDuiAmountString
<string> - Token amount as a string, accounting for decimals.
Example
For more details on Solana network providers, please refer to the link below.
Last updated