General layout of the XM SDKs
All the crosschain SDKs share the same interface, with a few blockchain-specific methods occuring on some SDKS.
To demonstrate the general layout of the SDKs, let's use the EVM crosschain SDK for the web.
Creating an SDK instance
Start by instantiating the SDK class using a RPC url.
The create method will ping the RPC and return an instance of the SDK connected to the RPC.
Changing the RPC URL
You can assign a new rpc url as shown:
Reading Blockchain data
You can access now acess Blockchain data using the helper methods provided by the SDK. For example, to read an address balance:
You can access additional methods for reading blockchain data by exploring the provider
object inside the SDK instance.
For example, to get the latest block on Ethereum:
Connecting a private key
To create and sign payloads, you need to attach your private key to your SDK instance.
The connectWallet
method returns the wallet
object that holds your private key inside the SDK instance.
You can now check the public key of your connect wallet.
Creating a single transaction
You can create transaction to send funds to addresses using the provided methods.
The preparePay
method creates a transaction to transfer funds to a destination address. It also signs the transaction using the connected private key. It returns the payload ready to be used in a DEMOS transaction.
Creating multiple transactions
You can also create a list of transaction to transfer funds.
The prepareTransfers
method creates and signs a list of transaction to transfer funds in the order of appearance.
Cleaning up
When you no longer need the instance, disconnect the rpc and your wallet.
Last updated