Coder Social home page Coder Social logo

nam-dam / merkle-distributor Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 2.0 237 KB

A smart contract that distributes a balance of tokens according to a Merkle root for NEAR Protocol.

License: GNU General Public License v3.0

TypeScript 47.05% Rust 51.34% Makefile 0.87% Shell 0.74%
rust near merkle-distributor smart-contract near-protocol airdrop merkle

merkle-distributor's Introduction

Merkle Distributor

Open in Gitpod

A program for distributing tokens efficiently via uploading a Merkle root.

This program is largely based off of Uniswap's Merkle Distributor.

Prerequisites

If you're using Gitpod, you can skip this step.

  • Make sure Rust is installed per the prerequisites in near-sdk-rs.
  • Make sure near-cli is installed.

Explore this contract

The source for this contract is in contracts/merkle-distributor/lib.rs.

Building this contract

Run the following, and we'll build our rust project up via cargo. This will generate our WASM binaries into our target/ directory. This is the smart contract we'll be deploying onto the NEAR blockchain later.

cargo build --target wasm32-unknown-unknown --release

Testing this contract

We have some tests that you can run. For example, the following will run our simple tests to verify that our contract code is working.

cargo test -- --nocapture

Using this contract

Quickest deploy

You can build and deploy this smart contract to a development account. Dev Accounts are auto-generated accounts to assist in developing and testing smart contracts. Please see the Standard deploy section for creating a more personalized account to deploy to.

near dev-deploy --wasmFile target/wasm32-unknown-unknown/release/merkle_distributor.wasm

Behind the scenes, this is creating an account and deploying a contract to it. On the console, notice a message like:

Done deploying to dev-xxx

In this instance, the account is dev-xxx. A file has been created containing a key pair to the account, located at neardev/dev-account. To make the next few steps easier, we're going to set an environment variable containing this development account id and use that when copy/pasting commands. Run this command to set the environment variable:

source neardev/dev-account.env
export ACCOUNT_ID=aabbcc

You can tell if the environment variable is set correctly if your command line prints the account name after this command:

echo $CONTRACT_NAME
echo $ACCOUNT_ID

The next command will initialize the contract using the new method:

near call $CONTRACT_NAME initialize '{"owner_id": "aaa", "token_id": "bbb", "merkle_root": "bbb"}' --accountId $CONTRACT_NAME

To claim:

near call $CONTRACT_NAME claim '{"index": 0, "amount": 100, "proof": ["xxx"]}' --accountId $ACCOUNT_ID

Notes

  • To generate merkle_tree, using command
yarn generate-merkle-root -i scripts/example.json -o merkle.json
  • The output tree will be located in merkle.json
  • Using merkleRoot and proof for calling contract using near-cli

merkle-distributor's People

Contributors

namqdam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

sbnair fospring

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.