A how-to guide for semi-custodial wallets on Solana

Semi-custodial wallets are more secure crypto wallets with partial custody of keys. This article shows the steps for creating a semi-custodial wallet on Solana.

Cryptocurrencies are stored in digital wallets called crypto wallets. Semi-custodial wallets are more secure crypto wallets with partial custody of keys. This article shows the steps for creating a semi-custodial wallet on Solana.

Crypto is becoming a mainstream investment choice nowadays, with a considerable number of public figures and senior businessmen investing a fortune in them. A Crypto-wallet is an application used for storing and trading crypto-currencies, very similar to traditional wallets, used to store real-time currencies. They are mainly of two types, namely custodial and non-custodial wallets. The key difference between these two is the custody of private keys. In custodial wallets, the private keys of the wallet are managed by a third-party organization, whereas in non-custodial wallets the private keys of the wallet are managed by the owners of the wallet itself.

As more and more people are jumping on board with cryptocurrencies for business ventures or simply as an investment opportunity, the question arises, of whether to choose a custodial or non-custodial wallet for storing your crypto funds. Both types have their advantages and limitations. In custodial wallets, as a third party holds the private keys, the backup and recovery of wallet data are effortless. But in terms of security, the entire authority lies with the third-party wallet service provider. Whereas non-custodial wallets are more secure in this department, as the private keys are stored with the user, but in case they lose the keys, the data will no longer be recoverable.

Semi-custodial wallets are the solution that combines the best of both worlds. Semi-custodial wallets divide the private key into two parts. One part of the key is stored with the user, and the other part is stored with the wallet service provider. This has a few advantages.

  • In terms of security, the entire key is not stored in one place, thus minimizing the chances of compromise.
  • Access and recovery of the wallet are easier since only a part of the private key is stored with the user. The part which is stored with the user may be common key phrases that are easy to remember.

Now, let’s see how we can create a semi-custodial wallet on Solana using SHYFT APIs.

Read SHYFT API Documentation here.

Semi-Custodial Wallets — Usage example

In this article, we will attempt to create a semi-custodial wallet for one particular user. We will accept the email and password from the user, and a new semi-custodial wallet will be created using the password provided. Once done, we will attempt to airdrop an NFT to the newly created wallet. The details of the NFT will be emailed to the email address provided by the user.

Before getting started

**Authentication: Getting your Shyft API key
**x-api-key is an authentication parameter, which gives you access to SHYFT APIs. You can get your own API Key from the SHYFT website. Just signup with your email id here and you can get it for free.

Creating a Semi-custodial wallet on Solana

**Getting Details from the user.
**We have created a simple form to accept the email id and password from the user. This can be done using HTML forms, react, or any other UI tools as per requirement.

Press enter or click to view image in full size

A simple form to accept the email and password from the user. The password will be used to create a semi-custodial wallet and the details of the created wallet will be delivered to the email.

**Creating a semi-custodial wallet
**There are several ways of creating semi-custodial wallets on Solana. However, we have chosen one of the simplest methods to create a semi-custodial wallet on Solana, which is using SHYFT APIs. SHYFT provides a series of Web3 APIs for almost all operations on Solana Blockchain, which include APIs for NFTs, Fungible Tokens, Wallets, and NFT Marketplace.

Let’s see how we can create a semi-custodial wallet using Shyft’s API-based solution. The endpoint for the API call.

POST <https://api.shyft.to/sol/v1/semi_wallet/create>

This API accepts the x-api-key parameter in the header, which is an authorization parameter used by SHYFT for validating its users. You can get your own x-api-key from the SHYFT website for free here. The Content-Type for this API request is application/json.

Parameters required for this API call password: The partial password for the semi-custodial wallet that will be with the user. In our case, we have used a form to collect the details from the user. The password can also be generated at random and shared with the user.

Once successfully executed, the response returned looks somewhat like this.

{    
    "success": true,
    "message": "Semi custodial wallet created successfully",
    "result": {
        "wallet_address": "7pu5mcx2N9bQwqfEe8aQkTzG6zrd9rsFArcvbeY93RkN"         }
}

The address specified in the wallet_address field is the wallet address of the newly created wallet.

Airdropping an NFT to the newly created wallet

Once we have created the wallet, we can use it as a regular Web3 wallet on Solana. We can transfer SOL, airdrop tokens, or even an NFT to this wallet. Let’s try to airdrop an NFT to this wallet, also using SHYFT APIs. The API endpoint for airdropping NFTs

POST <https://api.shyft.to/sol/v1/nft/mint_detach>

All SHYFT APIs accept x-api-key parameter in the header, which is an authorization parameter used by SHYFT for validating its users. You can get your own x-api-key from the SHYFT website for free here. The Content-Type for this API request is application/json.

Get Team Shyft’s stories in your inbox

Join Medium for free to get updates from this writer.

Parameters for this API call

  • network: Selects the Solana network cluster, which can be either devnet, testnet or mainnet-beta. The NFT which is being minted should be on this network.
  • wallet: Accepts the wallet address which has the mint authority of the NFT being minted.
  • master_nft_address: Accepts the address of the NFT being minted.
  • receiver: Accepts the address of the wallet to which the NFT will be minted. In our case, this will be the address of the newly created semi-custodial wallet.

This API returns an encoded_transaction that requires a signature from the wallet address specified in the wallet parameter. To know more about the parameters of this API call, please refer to our dev docs here, or you can also refer to our article on minting NFTs for a step-by-step solution.

To know about Signing Transactions on Solana, you can follow our dev guide here, or you can also check our GitHub repo for all the functions required to sign encoded transactions. Once signed successfully, the NFT will be minted and added to the newly created semi-custodial wallet.

Read SHYFT API Documentation here.

**The Next Steps
**Once the minting process is complete, we can go on and share the wallet details (the public wallet address) and the NFT details with the user via email collected on the first step (using Mailchimp or any transactional mail service). This is pretty much all about the application we attempted to create. However, there is so much more we can do with semi-custodial wallets, including decrypting the wallet or getting the private/public key pair.

Press enter or click to view image in full size

Sharing the details of the NFT and wallet on the email address provided by the user

More on Semi-Custodial Wallets

**Getting the keypair of the semi-custodial wallet
**The API endpoint for getting the keypair of the semi-custodial wallet.

GET <https://api.shyft.to/sol/v1/semi_wallet/get_keypair>

All SHYFT APIs accept x-api-key parameter in the header, which is an authorization parameter used by SHYFT for validating its users. You can get your own x-api-key from the SHYFT website for free here. The Content-Type for this API request is application/json.

Parameters required for this API call

  • password: The password for your wallet which is with you. By default, this is the password that you set while creating the wallet unless you have updated the password using SHYFT APIs.
  • wallet: Wallet address of the semi-custodial wallet which is being fetched.

Read SHYFT API Documentation here.

The sample response contains the public and private keys of the wallet.

{
    "success": true,
    "message": "Keypair of the wallet",
    "result": {
        "publicKey": "7pu5mcx212fwqfEe8aQkTzG6zrd9rsFArcvbeY93RkN",
        "secretKey": "4Zko3JAtroEL8sKPSYMBWpiRpGoetAqG4mofRU83tn5XwgC97EiMbxQ8VYXTGrih5bcwmDXRHgUnKgAqM32QN8r"
    }
}

Decrypting a semi-custodial wallet

The API endpoint for decrypting a semi-custodial wallet.

GET <https://api.shyft.to/sol/v1/semi_wallet/get_keypair>

All SHYFT APIs accept x-api-key parameter in the header, which is an authorization parameter used by SHYFT for validating its users. You can get your own x-api-key from the SHYFT website for free here. The Content-Type for this API request is application/json.

Parameters required for this API call

  • password: The password for your wallet which is with you. By default, this is the password that you set while creating the wallet unless you have updated the password using SHYFT APIs.
  • wallet: Wallet address of the semi-custodial wallet which is being decrypted. You can only decrypt a semi-custodial wallet you have created.

Read SHYFT API Documentation here.

The sample response contains the encrypted private key and the decryption key as well.

{
    "success": true,
    "message": "Decryption Data",
    "result": {
        "encryptedPrivateKey": "pYFpkcU9P4wcSo3xrTzH4cvAZFAPBjEQuc181P5t9UAtym7NgxHpfCYgR6f7ikhZYRJ3x4citPCTA4KKjZFnCtWMUjh5d67gzKbiS2BEmiph4E4raJfnSvR1adzPCn9VGTJZafb3CnMKmD",
        "decryptionKey": "{\\"salt\\":\\"HhXEQgWV8scfSFaKyroKg2\\",\\"kdf\\":\\"pbkdf2\\",\\"digest\\":\\"sha256\\",\\"iterations\\":100000,\\"nonce\\":\\"ELWuGTCFDCK13jYx9d7pHnJrnthMnxpLo\\"}"
    }
}

So, that’s pretty much all about semi-custodial wallets on Solana with SHYFT APIs. If you liked this article, feel free to check out our other articles on creating a token airdrop campaign on Solana (series) or airdropping tokens to multiple wallets on Solana. We hope you have a great time building dApps on Solana using SHYFT APIs. Happy Hacking!

Resources

SHYFT API Documentation
Shyft Website
Get API Key
GitHub
Join our Discord
Try out our APIs on Swagger UI