1

What is best practice for running Airdrops periodically? For example Airdrop daily rewards to holders of a certain token? Is something like this even possible to do while just using an on-chain program?

2 Answers 2

1

If you're using Node.js, then you can use libraries such as node-schedule to schedule a job which would run periodically at a certain interval.

const schedule = require('node-schedule');

// 0 * * * * means every 1 hour - https://cronexpressiontogo.com/every-1-hour
const job = schedule.scheduleJob('0 * * * *', function(){
  // add the function which would airdrop tokens over here
});
2
  • Thanks, I understand how you would set up something to run periodically (you could use a cron job as well). But I was wondering what was best practice and I gather from your answer it's an external script that invokes the instruction? Commented Dec 13, 2022 at 15:28
  • 1
    Oh! So you want to periodically airdrop the tokens under an on-chain program? If so, then you can take a look at Clockwork. They have an example for your use-case in their repository - github.com/clockwork-xyz/examples/tree/main/payments. Here is a list of all the examples - docs.clockwork.xyz/developers/examples
    – 0xMukesh
    Commented Dec 13, 2022 at 15:38
1

you can write a script to do that depending on the language you are using, if you are using javascript then you can use web3.js on solana to get started

just use the devnet and program a timer thread to airdrop you at intervals..

from 0xmukesh answer:

const schedule = require('node-schedule');

// 0 * * * * means every 1 hour - https://cronexpressiontogo.com/every-1-hour
const job = schedule.scheduleJob('0 * * * *', function(){
  // Establish new connect to devnet - websocket client connected to devnet will also be registered here
const connection = new Connection(clusterApiUrl("devnet"), "confirmed");

// Create a test wallet to listen to
const wallet = Keypair.generate();

// Register a callback to listen to the wallet (ws subscription)
connection.onAccountChange(
  wallet.publicKey(),
  (updatedAccountInfo, context) =>
    console.log("Updated account info: ", updatedAccountInfo),
  "confirmed"
);
});
1
  • Thanks for answering. See my comment on 0xmukesh's answer, but I'm wondering primarily about best practice. So let's say I have token A, and want to airdrop a certain amount to some accounts every 1 hour. Do I understand you correctly that I would run an external script that would perform this airdrop? Is there a better way perhaps? Perhaps there is an event for a particular Solana tick. Commented Dec 13, 2022 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.