GithubHelp home page GithubHelp logo

friedger / clarity-smart-contracts Goto Github PK

View Code? Open in Web Editor NEW
79.0 16.0 34.0 2.49 MB

Collection of Smart Contract for Stacks Blockchain in Clarity

License: MIT License

TypeScript 62.19% Clarity 37.11% JavaScript 0.70%
clarity stacks blockstack smart-contracts

clarity-smart-contracts's Introduction

Gitpod ready-to-code

Clarity Smart Contracts

A collection of various smart contracts written in Clarity. They run on the Stacks blockchain.

See also original Clarity tutorials by Blockstack.

Repositories with Smart Contracts

  • Swapr Trustless token exchange.
  • Flexr Token with an elastic supply, guaranteed by design to be uncorrelated to other tokens.
  • Stackstarter Crowdfunding
  • Marketplace Marketplace (NFTs that can get disabled + market).
  • Loopbomb Marketplace Marketplace for art NFTs and others.
  • Profit sharing token Token with included profit sharing on resale.
  • Blind Poll Anonymous polls, where all submitted answers will be sealed until they're revealed by participants after the poll is closed.
  • Highscore Simple list of submitted scores.
  • Redistribution Pot for redistributing funds.
  • Endless list A bottomless, paged, list of items.
  • Stacks loans Loans with fixed interest rates.
  • Advent calendar Open one door each day, open to everybody to add new doors.

More examples on

Smart Contracts in this Repository

This repo is gitpod ready. Click the gitpod button to start editing and running the contracts. (Read more about Clarity Web IDE (gitpod based))

.
+-- contracts
|    +-- license (OI License - contract to handle licenses for using UI apps, not data apps)
|    +-- tokens  (Token contracts with various properties)
|    +-- experiments (All the rest)
+-- test
|    +-- integration (Tests that run on mocknet or testnet)
|    +-- unit (Test that run on clarity VM only)

Documented Contracts

Escrow contract: Simple token transfer via 3rd party (contract account). Video of demo

Flip coin contract: Random coin flipping, users can bet on the outcome.

clarity-smart-contracts's People

Contributors

dependabot[bot] avatar friedger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clarity-smart-contracts's Issues

Simplify equality reducer

The value-tuple state in flip-coin.clar can be reused and just passed along until and after a match, simplifying the implementation and making it more efficient:

(define-private (is-even (item (buff 1)) (value-tuple {value: (buff 1), result: (buff 1)}))
(let ((val (get value value-tuple)))
(if (is-eq item val )
{value: val, result: 0x00}
{value: val, result: (get result value-tuple)}
)
)
)

=>

(define-private (is-even (item (buff 1)) (state {value: (buff 1), result: (buff 1)})) 
   (let ((val (get value state))) 
     (if (is-eq item val) 
       {value: val, result: 0x00} 
       state))) 

Also, consider turning result into a boolean initially set to false to eliminate the test on the result of the reduction:

(define-read-only (even (value (buff 1)))
  (get result (fold is-even even-buffer {value: value, result: false})))

Animal Kingdom contract can't mint new tokens

Calling mint-next throws the following error:

Transaction execution error: 
Unchecked(TypeValueError(ListType(ListTypeData { max_len: 10, entry_type: UIntType }), List(ListData { data: [UInt(1)], type_signature: ListTypeData { max_len: 11, entry_type: UIntType } })))

Cancel listing properties

When i try to write function for cancel listing i got error and issue:

use of unresolved function 'tup-get'clarity
(let ((name1 expr1) (name2 expr2) ...) expr-body1 expr-body2 ... expr-body-last) -> A
Description The let function accepts a list of variable name and expression pairs, evaluating each expression and binding it to the corresponding variable name. let bindings are sequential: when a let binding is evaluated, it may refer to prior binding. The context created by this set of bindings is used for evaluating its body expressions. The let expression returns the value of the last such body expression. Note: intermediary statements returning a response type must be checked

Cancel listing function:
(define-public (cancel-listing (listing-id uint))
(let ((listing (at-block listings listing-id)))
(asserts! listing err-unknown-listing)
(asserts! (is-eq tx-sender (get listing maker)) err-unauthorised)
(asserts! (> (get listing expiry) block-height) err-listing-expired)
(ok (map-delete listings key-tuple listings listing-id))
)
What i am doing wrong?

Corrections for escrow contract instructions

Hey Friedger! First off, thank you for putting all this together, I think it's a great resource!

@HaroldDavis3 and I were walking through the setup on his machine, and I noted a few differences in his experience versus what you have in the instructions. A few notes below:

HTTPS links versus SSH

There are a few people coming up with "permissions errors" when they try to follow the instructions, and it's because they are using the SSH links in the tutorial versus HTTPS without having SSH configured. It might be worth either noting this at the beginning for people to use the correct link?

Wrong repo on stacks-transactions-js

Under Stacks Transaction library for Javascript, the repo listed is actually the stacks-blockchain one when it should be stacks-transactions-js:

git clone [email protected]:blockstack/stacks-blockchain.git <-- the *other* stacks-thing :)
cd stacks-transactions-js
git checkout feature/tx-broadcast

Moving around directories with cd ..

This part may be a bit confusing for people who are downloading/using LInux for the first time, as they may not realize what directory they are in or what's happening. If they cd .. in the wrong place or a new terminal window, it creates an issue.

Maybe have them create a terminal window for each git clone operation? That way it'd land in their home directory every time?

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.