Quickstart
Last updated
Was this helpful?
Last updated
Was this helpful?
In this quickstart, you will learn how to automate a SOL transfer using Clockwork. We will install the Clockwork CLI and spawn a Clockwork thread from a Typescript application. Within 10 minutes, you will have your first automation up and running.
Let's begin by creating a new vanilla Node Typescript project:
Create a new tsconfig.json
file:
Create a new package.json
file with the below content. The main dependencies you really need in your project are the and Anchor.
After this, create a new file called main.ts
. Import the necessary libraries and set up a Clockwork provider.
Next, we'll prepare a SystemTransfer
instruction and automate it with a Clockwork thread. Threads are the basic building blocks of automations on Solana. Every thread has a trigger condition and a set of instructions to run. In the code sample below, we create a thread that schedules a SOL transfer to happen every 10 seconds.
We can see the threadCreate
function asks for 5 arguments. These include some basic information needed to initialize the thread account.
authority
– The owner of the thread. This account must be the transaction signer and will have permission to delete, pause, resume, stop, and update the thread.
id
– An identifier for the thread (can also use buffer or vec u8).
instructions
– The list of instructions to execute when the trigger condition becomes valid.
trigger
– The trigger condition for the thread. When this condition is valid, the thread will begin executing the provided instructions.
Now that we have Clockwork installed, we can go ahead and spin up a local Clockwork node:
In a separate terminal window, we'll run the test:
And voila:
Threads are an automation primitive for Solana.
You can use threads to automate any program instruction on Solana.
amount
– The number of lamports to fund the thread account with. Remember to provide a small amount of SOL. Read more about how fees are calculated .
Now we need to get our app running. If you have not done so already, you will need to install the Clockwork CLI by running the cargo command below. If you face any trouble here, please refer to the docs.
You can now watch your automation run all on its own. Grab the Clockwork explorer link that was printed out to the console. Using the Clockwork explorer, you can get simulation logs and inspect your thread. For example, here's mine:
Of course you can also look up your thread account in your favorite Solana explorer. You can alternatively use the Solana CLI to stream program logs by running the command provided below. Here's that was created in a test on May 24th, 2023.
allow you to define when a thread should begin execution.
Threads must be funded with a small amount of SOL to pay for .
Many more examples can be found in the .
Ask questions on .