Near Logo

Recurring transaction in Near Protocol

NEAR is a decentralized application platform that makes blockchain accessible to everyday people who are excited for the future of the Open Web. A web that is more private, more secure, and puts people in control of their money, data, and identity. NEAR’s purpose is to enable community-driven innovation to benefit people around the world.

Wondering what makes NEAR special?

  • NEAR is the inevitable evolution of existing platforms like Bitcoin and Ethereum, which did allow developers to write smart contracts and build Dapps but face critical challenges like high transaction charges (fees) and scaling issues
  • NEAR is the fastest path to market for builders to create blockchain applications that are as easy to use as they are to build. It uses common development patterns and programming languages that are immediately familiar to web developers.
  • NEAR is designed to work with existing blockchain platforms and is easy for existing applications to migrate to. NEAR uses the Ethereum Virtual Machine and Web Assembly so that builders can seamlessly swap from Ethereum to NEAR (and back) on the NEAR Rainbow Bridge to leverage the performance, security, and favorable economics of NEAR without having to rebuild their applications or smart contracts.

Considering these advantages, today, I would like to show on how one can get started with simple contract written in Assembly Script.


yarn add -D near-sdk-as

Create a testnet account

Navigate to and click on "Create Account".

Install NEAR-CLI

npm install -g near-cli

After the setup is done, here is the code snippet of the contract where we increment/decrement/reset or get the value of variable counter.

Once you have the contract, you can use “near-cli” to deploy the contract on testnet using your testnet account.

near deploy --accountId example-contract.testnet --wasmFile out/example.wasm

Now that we have deployed our smart contract, we would like to create a schedular which would increment the counter for every 5 mins. In order to do this, we are gonna use Croncat, decentralised schedular for blockchain transactions.

Now we need to create a task for the schedular. In order to do that, I would run a cli command as shown below:

near call example-contract.testnet create_task '{"contract_id": "example-contract.testnet","function_id": "incrementCounter","cadence": "0 */5 * * * *","recurring": true,"deposit": "10","gas": 2400000000000}' --accountId YOUR_NEAR_ACCT.testnet --amount 10

You will get a task hash upon successful creation. Save this hash as its your access to monitor and update the task in the future.

Very important thing to note: the --amount flag is how you are attaching real NEAR tokens to your task. If you specify a “deposit” of 10, and then the --amount is less than 10, the task will never run.

Here is how, you can schedule recurring transaction in near protocol.

Thanks for dropping by !!!