Skip to main content

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.

  1. Provided a PersistentStorageClient to store and manage the keyshares.
  2. Spin up the server, this example uses a local server for testing.
  3. Create a Cloud Client to connect to the server.
  4. Created a eddsa session using the createDuoEddsaSession function. This uses cloud client and storage client to create a session.
  5. Create a new Keyshare if not found in the storage client, otherwise read it from the storage client. This is done using the keygen function of the session.
  6. Convert the public key to an Ed25519HDPublicKey.
  7. Create a solana rpc client.
  8. Fund the wallet using the sendSolToAddress function. 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 the sendSolToAddress function.) The response is decoded using the classes FaucetSuccessResponse and FaucetErrorResponse.
  9. To wait for the transaction to be confirmed, we use the waitForTransactionConfirmation function.
  10. Create the recipient address.
  11. Create the transfer instruction.
  12. Compile the message.
  13. Convert the message to bytes.
  14. Sign the message using the sign function of the session.
  15. Create the signed transaction.
  16. Send the transaction and wait for confirmation.
  17. Wait for the transaction to be confirmed and print the balance of the wallet and the recipient address.