Invoke Solana Lambda method as the developer (Zero-Friction and Gasless)

In this tutorial, we will discuss how to make transactions on Solana in a gasless manner by leveraging MetaKeep’s Lambda Infrastructure. We will discuss transactions with a single signer and transactions with multiple signers. After this tutorial, you will be able to make a transaction on Solana without worrying about transaction fees, Solana nodes, gas tokens etc.

Invoking Solana Contracts using MetaKeep Lambda

In this tutorial, we will call the built-in Memo Program of Solana using MetaKeep Lambda. The Memo Program allows you to log the memo, as well as any verified signer addresses, to the transaction log, so that anyone can easily observe memos and know they were approved by zero or more addresses by inspecting the transaction log from a trusted provider.

You can find an end-to-end working demo here.

Step 1: Create the transaction object with the memo log instructions

You can use @solana/web3.js to create the transaction object.

Step 2: Make A POST request to the API.

To invoke without any external signers, you need to provide the following fields in the request body:

{
    "serializedTransactionMessage" : "0x1234....",
    "reason" : "Reason for Invocation"
}

If there are external signers, you also need to provide the signers with their signatures in the request body. The request body will look like this:

{
    "serializedTransactionMessage" : "0x1234....",
    "reason" : "Reason for Invocation",
    "signatures": [
        {
            "publicKey": "2k1ZTti7uQ1BZyMTscVLbzm3H74ncv2JdtLTio3FQxpb",
            "signature": "0x1234...."
        },
        {
            "publicKey": "HLETGSnF62q7ANP8SoWe7sxq7qrG3CEH6rJJhjaPadn8",
            "signature": "0x1234...."
        }
    ]
}

Running the Demo

You can find an end-to-end working demo here. Follow the steps to run the demo:

Step 1: Update the .env file with the API Key.

Update the .env file with the MetaKeep Solana API key. You can find the API key in the MetaKeep Dashboard.

Step 2: Run the script

Navigate to the solana/lambda/scripts directory, Then run the following command to invoke without external signers:

npm install
npm run invoke

This will make a call to the Memo Program of Solana using your developer account.

Now let's invoke with external signers. Run the following command:

npm run invokeWithExternalSigners

This will make a call to the Memo Program of Solana using your developer account and 1 external signer.

Note that you don't need to hold any gas tokens to make the transaction. MetaKeep will take care of the transaction fees.

Next Steps

Voila! You have invoked the memo program on Solana using MetaKeep Lambda with one REST API Request 🎉🎉. We will take a look at how to invoke MetaKeep Lambda for end-users in the next tutorials.