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.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:provider object inside the SDK instance.
For example, to get the latest block on Ethereum:
The shape of the
provider object is SDK specific. Please find the link to the API reference at the bottom of the specific crosschain SDK documentation page.Connecting a private key
To create and sign payloads, you need to attach your private key to your SDK instance.connectWallet method returns the wallet object that holds your private key inside the SDK instance.
The shape of the
wallet object is SDK specific. Please find the link to the API reference at the bottom of the specific crosschain SDK documentation page.Creating a single transaction
You can create transaction to send funds to addresses using the provided methods.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.
The
prepareTransfer method is an alias of the preparePay method.Creating multiple transactions
You can also create a list of transaction to transfer funds.prepareTransfers method creates and signs a list of transaction to transfer funds in the order of appearance.