Solana Integration
Transfer SOL and interact with Solana chains using solana_sdk and Silent Shard SDK
Complete github repository example can be found here
Workflow
The example shows 2 examples, one is to transfer SOL and the other is to transfer SOL with a token. Both uses the same workflow with minor differences.
- Provided a
PersistentStorageClientto store and manage the keyshares. - Spin up the server, this example uses a local server for testing.
- Create a Cloud Client to connect to the server.
- Created a eddsa session using the
createDuoEddsaSessionfunction. This uses cloud client and storage client to create a session. - Create a new Keyshare if not found in the storage client, otherwise read it from the storage client. This is done using the
keygenfunction of the session. - Convert the public key to an Ed25519HDPublicKey.
- Create a solana rpc client.
- Fund the wallet using the
sendSolToAddressfunction. The example uses the Solana faucet server to fund the wallet provided by the Silence Laboratories for hassle free testing. (The api has a rate limit if query exceeds the limit, you can use your own faucet server by changing thesendSolToAddressfunction.) The response is decoded using the classesFaucetSuccessResponseandFaucetErrorResponse. - To wait for the transaction to be confirmed, we use the
waitForTransactionConfirmationfunction. - Create the recipient address.
- Create the transfer instruction.
- Compile the message.
- Convert the message to bytes.
- Sign the message using the
signfunction of the session. - Create the signed transaction.
- Send the transaction and wait for confirmation.
- Wait for the transaction to be confirmed and print the balance of the wallet and the recipient address.