{"id":16560258,"url":"https://github.com/friedger/clarity-marketplace","last_synced_at":"2025-10-28T21:30:34.966Z","repository":{"id":53717361,"uuid":"288178806","full_name":"friedger/clarity-marketplace","owner":"friedger","description":"Clarity smart contract of a marketplace","archived":false,"fork":false,"pushed_at":"2024-10-18T11:28:22.000Z","size":604,"stargazers_count":16,"open_issues_count":0,"forks_count":8,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-10-19T14:13:43.840Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Clarity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/friedger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-17T12:49:26.000Z","updated_at":"2024-10-18T11:28:26.000Z","dependencies_parsed_at":"2022-09-10T14:11:09.961Z","dependency_job_id":null,"html_url":"https://github.com/friedger/clarity-marketplace","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friedger%2Fclarity-marketplace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friedger%2Fclarity-marketplace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friedger%2Fclarity-marketplace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friedger%2Fclarity-marketplace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/friedger","download_url":"https://codeload.github.com/friedger/clarity-marketplace/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238720430,"owners_count":19519348,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T20:28:44.111Z","updated_at":"2025-10-28T21:30:29.641Z","avatar_url":"https://github.com/friedger.png","language":"Clarity","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Clarity Marketplace\n\n![marketplace](marketplace.jpg)\n\nClarity smart contract for a marketplace of tradable assets (some kind of basic NFTs)\n\n(Inspired by the marketplace of monstereos.io)\n\nThis is a submission to the CLARITY HACK of the Stacks 2.0 Hackathon Series.\n\n## Smart Contracts\n\nThe main contract `market.clar` describes the marketplaces. `tradables.clar` defines the interface (`trait`) of tradable assets. There are two examples of tradable assets:\n\n- `monsters.clar`: a simple tamagoshi like monster that needs to be fed every 6 blocks\n- `constant-tradables.clar`: a dump asset that always belongs to the contract and transferring assets won't change ownership.\n\nThe marketplace supports all assets that have are NFTs with uint keys.\n\n### Public functions of the marketplace\n\nThe marketplace provides two functions for a bidder for a token:\n\n- `bid`: allows to publish a price for a tradable asset that is defined by a contract implementating the `tradables-trait` and by an unsigned integer.\n- `pay`: after the bid was accepted by the current owner, the bidder can pay for the asset using this function and the asset will be transferred to the bidder.\n\nThe owner of a tradable asset can choose to accept a bid from all current bids:\n\n- `accept`: allows to accept a bid for the tradable asset. The asset will be transferred to the marketplace until the bidder has paid the price.\n- `cancel`: allows to cancel an accepted bid that was not yet paid, e.g. because the bidder disappeared\n\n### Used features of Clarity\n\nThe marketplace contract uses\n\n- a map to store offers.\n- the contract as an escrow for transferring assets.\n- `traits` to handle any kind of tradables assets. It makes use of `contract-of` to store the contract of the assets.\n- stx transfers and nft transfers within contract calls that benefit from the post condition feature of the stacks chain.\n\n## Notes\n\n- Testing using the clarity-js-sdk is currently not possible as the latest SDK (0.2.0) does not support `contract-of` function. (Workaround: copy the most recent binary `clarity-cli` to the `node_modules/@blockstack/clarity-native-bin/.native-bin` folder of this project)\n- Deploying to testnet works (run `npx ts-node scripts/market.ts`), however, due to issue [#92](https://github.com/blockstack/stacks-transactions-js/issues/92) it is not possible to call functions with traits as arguments.\n\n### Simplified Marketplace\n\nAs a consequence, a simplified marketplace is defined in folder `contract-simple`. The marketplace can only\ntrade monsters (defined in `monsters.clar`). The functions are the same, the difference is that traits are not used.\n\nTo test the simple contract, run `yarn mocha test/market-simple.ts`.\nWhile it is possible to initialize the VM with accounts with set amounts of STX, the current SDK does not support this feature. Therefore, the test does not include sucessful calls to the `pay` function.\n\n## Deployment\n\nThere is a script in folder `scripts` called `market.ts` that can be used to deploy the contracts to the testnet. Replace the location of the keychain.json file ontop of the script. Then run\n\n```\nnpx ts-node scripts/market.ts\n```\n\n## Future Work\n\nAfter the issues mentioned in Notes have been solved the following tasks should be done:\n\n- build a web ui for making and accepting bids\n- run a server that maintains the list of current bids for assets. The list is not maintained on-chain because the list can be easily recreated from the history of relevant transactions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffriedger%2Fclarity-marketplace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffriedger%2Fclarity-marketplace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffriedger%2Fclarity-marketplace/lists"}