{"id":21519765,"url":"https://github.com/hashi7412/nft-staking","last_synced_at":"2026-05-17T21:03:05.798Z","repository":{"id":162185481,"uuid":"562132063","full_name":"hashi7412/nft-staking","owner":"hashi7412","description":"Varda NFT market implementation using the PoC backbone for NFT Marketplaces on NEAR Protocol.","archived":false,"fork":false,"pushed_at":"2022-11-05T12:12:49.000Z","size":135,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-24T04:39:25.052Z","etag":null,"topics":["hashi7412","nearprotocol","nft","poc","shinobi","solana","staking"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hashi7412.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-11-05T12:11:30.000Z","updated_at":"2023-06-22T20:34:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"08980490-4cb2-4ab2-bf60-b178548ea81a","html_url":"https://github.com/hashi7412/nft-staking","commit_stats":null,"previous_names":["hashi7412/nft-staking","partner20307/nft-staking","squaremost/nft-staking"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashi7412%2Fnft-staking","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashi7412%2Fnft-staking/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashi7412%2Fnft-staking/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashi7412%2Fnft-staking/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hashi7412","download_url":"https://codeload.github.com/hashi7412/nft-staking/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244075635,"owners_count":20393979,"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":["hashi7412","nearprotocol","nft","poc","shinobi","solana","staking"],"created_at":"2024-11-24T01:00:03.903Z","updated_at":"2026-05-17T21:03:00.758Z","avatar_url":"https://github.com/hashi7412.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Varda NFT market implementation\n\nUsing the PoC backbone for NFT Marketplaces on NEAR Protocol.\n\n[Reference](https://nomicon.io/Standards/NonFungibleToken/README.html)\n\n## ToDo:\n- [ ] add stNEAR as a trading ft\n- [ ] implement [Narwallet](https://narwallets.github.io/meta-pool/) with Varda Vault NEARNFT dispay for unlockable content\n\n## Varda strategy game and staking mechanics explained\n\n[![Varda strategy game and staking mechanics explained](https://img.youtube.com/vi/xM8EhLeGOEI/0.jpg)](https://www.youtube.com/watch?v=xM8EhLeGOEI)\n\n## Varda cultural reference\n\n[![Varda cultural reference](https://img.youtube.com/vi/6rOkVq8qPrs/0.jpg)](https://www.youtube.com/watch?v=6rOkVq8qPrs)\n\n[Varda Tokenomics](https://varda-vision.medium.com/)\n\n## Progress:\n- [x] basic purchase of NFT with FT\n- [x] demo pay out royalties (FTs and NEAR)\n- [x] test and determine standards for markets (best practice?) to buy/sell NFTs (finish standard) with FTs (already standard)\n- [x] demo some basic auction types, secondary markets and \n- [x] frontend example\n- [x] first pass / internal audit\n- [ ] connect with bridged tokens e.g. buy and sell with wETH/nDAI (or whatever we call these)\n- [ ] add ability to migrate NFT to ethereum blockchain using rainbowbridge/aurora\n\n## Notes:\n\nHigh level diagram of NFT sale on Market using Fungible Token:\n![image](https://user-images.githubusercontent.com/321340/113903355-bea71e80-9785-11eb-8ab3-9c2f0d23466f.png)\n\nRemove the FT steps for NEAR transfers (but nft_transfer_payout and resolve_purchase still the same).\n\nDifferences from `nft-simple` NFT standard reference implementation:\n- anyone can mint an NFT\n- Optional token_type\n- capped supply by token_type\n- lock transfers by token_token\n- enumerable.rs\n\n## Working\n\n**Frontend App Demo: `/test/app.test.js/`**\n- install, deploy, test `yarn \u0026\u0026 yarn test:deploy`\n- run app - `yarn start`\n\n**App Tests: `/test/app.test.js/`**\n- install, deploy, test `yarn \u0026\u0026 yarn test:deploy`\n- if you update contracts - `yarn test:deploy`\n- if you update tests only - `yarn test`\n\n# NFT Specific Notes\n\nAssociated Video Demos (most recent at top)\n\n[![NEAR Protocol - Demo NFT Marketplace Walkthough](https://img.youtube.com/vi/AevmMAtkIr4/0.jpg)](https://www.youtube.com/watch?v=AevmMAtkIr4)\n\n[![Live App Review 19 - NFT Marketplace with Fungible Token Transfers and Royalty Distribution](https://img.youtube.com/vi/sGTC3rs8OJQ/0.jpg)](https://youtu.be/sGTC3rs8OJQ)\n\nSome additional ideas around user onboarding:\n\n[![NEAR Protocol - NFT Launcher \u0026 Easy User Onboarding Demo - Hackathon Starter Kit!](https://img.youtube.com/vi/59Lzt1PFF6I/0.jpg)](https://www.youtube.com/watch?v=59Lzt1PFF6I)\n\n# Detailed Installation / Quickstart\n\n#### If you don't have Rust\nInstall Rust https://rustup.rs/\n#### If you have never used near-cli\n1. Install near-cli: `npm i -g near-cli`\n2. Create testnet account: [Wallet](https://wallet.testnet.near.org)\n3. Login: `near login`\n#### Installing and Running Tests for this Example\n1. Install everything: `yarn \u0026\u0026 (cd server \u0026\u0026 yarn)`\n2. Deploy the contract and run the app tests: `yarn test:deploy`\n3. (WIP) Start server and run server tests: `cd server \u0026\u0026 yarn start` then in another terminal from the root `yarn test:server`\n\n#### Notes\n- If you ONLY change the JS tests use `yarn test`.\n- If you change the contract run `yarn test:deploy` again.\n- If you run out of funds in the dev account run `yarn test:deploy` again.\n- If you change the dev account (yarn test:deploy) the server should restart automatically, but you may need to restart the app and sign out/in again with NEAR Wallet.\n### Moar Context\n\nThere's 3 main areas to explore:\n- frontend app - shows how to create guest accounts that are added to the app contract via the nodejs server. Guests can mind NFTs, put them up for sale and earn NEAR tokens. When the guest has NEAR they can upgrade their account to a full account.\n- app.test.js (demos frontend only tests)\n\n### Owner Account, Token Account, etc...\n\nThe tests are set up to auto generate the dev account each time you run `test:deploy` **e.g. you will get a new NFT contract address each time you run a test**.\n\nThis is just for testing. You can obviously deploy a token to a fixed address on testnet / mainnet, it's an easy config update.\n\n#### Guests Account (key and tx gas sponsorship)\nWhen you run app / server tests. There's a contract deployed and a special account created `guests.OWNER_ACCOUNT_ID` to manage the sponsored users (the ones you will pay for gas fees while onboarding). This special \"guests\" account is different from the test guest account `bob.TOKEN_ID.OWNER_ACCOUNT_ID`. It is an account, different from the owner or token accounts, that manages the guests keys.\n\n#### Guest Accounts\nThe guest users can `claim_drop, ft_transfer_guest` and receive tokens from other users, e.g. in the server tests the owner transfers tokens to the guest account via API call and using client side code.\n\nThen, following the server tests, the guest transfers tokens to alice (who is a real NEAR account e.g. she pays her own gas).\n\nFinally, the guest upgrades themselves to a real NEAR account, something demoed in the video.\n\nIt's a lot to digest but if you focus on the `/test/app.test.js` you will start to see the patterns.\n# Background\n\nOne of the issues with onboarding new users to crypto is that they need to have crypto to do anything e.g. mint an NFT. A creator, artist or community might want to drop a bunch of free minting options to their fans for them to mint user generated content, but the audience has (1) no crypto to pay for fees (2) no wallet (3) no concept of crypto or blockchain; prior to the drop. \n\nSo let's solve these issues by allowing users to generate content the traditional Web2 way!\n\nWe do a demo of creating a \"guest\" named account for an app where the gas fees are sponsored by a special app account called \"guests.APP_NAME.near\". The guest account doesn't exist (sometimes called a virtual or contract account) until the user creates and sells and NFT that generates some NEAR tokens and then they can upgrade to a real account. Until then their name is reserved because only the app is able to create \"USERNAME.APP_NAME.near\".\n\nThis has many advantages for user onboarding, where users can use the app immediately and later can be upgraded to a full account. The users also don't have to move any assets - namely the fungible tokens they earned as a guest user. \n\n## Installation\n\nBeyond having npm and node (latest versions), you should have Rust installed. I recommend nightly because living on the edge is fun.\n\nhttps://rustup.rs/\n\nAlso recommend installing near-cli globally\n\n`npm i -g near-cli`\n\nEverything else can be installed via:\n`yarn`\n`cd server \u0026\u0026 yarn`\n\n## NEAR Config\n\nThere is only one config.js file found in `src/config.js`, this is also used for running tests.\n\nUsing `src/config.js` you can set up your different environments. Use `REACT_APP_ENV` to switch environments e.g. in `package.json` script `deploy`.\n\n## Running Tests\n\nYou can run unit tests in the Rust contracts themselves, but it may be more useful to JS tests against testnet itself.\n\nNote: to run the app and server tests make sure you install and start the server.\n- cd server\n- yarn \u0026\u0026 yarn start\n\nCommands:\n- `test` will simply run app tests against the contract already deployed. You can mess around with `app.test.js` and try different frontend stuff\n- `test:deploy` - will deploy a new dev account (`/neardev`) and deploy a new contract to this account, then run `test`\n- `test:server` - will test the server, make sure you start it (see \"Note\" above)\n- `test:unit` - runs the rust unit tests\n\nIf you've changed your contract or your dev account has run out of funds use `test:deploy`, if you're updating your JS tests only then use `test`.\n\n## Test Utils\n\nThere are helpers in `test/test-utils.js` that take care of:\n1. creating a near connection and establishing a keystore for the dev account\n2. creating test accounts each time a test is run\n3. establishing a contract instance so you can call methods\n\nYou can change the default funding amount for test accounts in `src/config.js`\n\n## Using the NEAR Config in your app\n\nIn `src/state/near.js` you will see that `src/config.js` is loaded as a function. This is to satisfy the jest/node test runner.\n\nYou can destructure any properies of the config easily in any module you import it in like this:\n\n```\n// example file app.js\n\nimport getConfig from '../config';\nexport const {\n\tGAS,\n\tnetworkId, nodeUrl, walletUrl, nameSuffix,\n\tcontractName,\n} = getConfig();\n```\nNote the export const in the destructuring?\n\nNow you can import these like so:\n```\n//example file Component.js\nimport { GAS } from '../app.js'\n...\nawait contract.withdraw({ amount: parseNearAmount('1') }, GAS)\n...\n```\n\n# React 17, Parcel with useContext and useReducer\n- Bundled with Parcel 2.0 (@next) \u0026\u0026 eslint\n- *Minimal all-in-one state management with async/await support*\n\n## Getting Started: State Store \u0026 useContext\n\n\u003eThe following steps describe how to use `src/utils/state` to create and use your own `store` and `StateProvider`.\n\n1. Create a file e.g. `/state/app.js` and add the following code\n```js\nimport { State } from '../utils/state';\n\n// example\nconst initialState = {\n\tapp: {\n\t\tmounted: false\n\t}\n};\n\nexport const { store, Provider } = State(initialState);\n```\n2. Now in your `index.js` wrap your `App` component with the `StateProvider`\n```js\nimport { Provider } from './state/app';\n\nReactDOM.render(\n    \u003cProvider\u003e\n        \u003cApp /\u003e\n    \u003c/Provider\u003e,\n    document.getElementById('root')\n);\n```\n3. Finally in `App.js` you can `useContext(store)`\n```js\nconst { state, dispatch, update } = useContext(store);\n```\n\n## Usage in Components\n### Print out state values\n```js\n\u003cp\u003eHello {state.foo \u0026\u0026 state.foo.bar.hello}\u003c/p\u003e\n```\n### Update state directly in component functions\n```js\nconst handleClick = () =\u003e {\n    update('clicked', !state.clicked);\n};\n```\n### Dispatch a state update function (action listener)\n```js\nconst onMount = () =\u003e {\n    dispatch(onAppMount('world'));\n};\nuseEffect(onMount, []);\n```\n## Dispatched Functions with context (update, getState, dispatch)\n\nWhen a function is called using dispatch, it expects arguments passed in to the outer function and the inner function returned to be async with the following json args: `{ update, getState, dispatch }`\n\nExample of a call:\n```js\ndispatch(onAppMount('world'));\n```\n\nAll dispatched methods **and** update calls are async and can be awaited. It also doesn't matter what file/module the functions are in, since the json args provide all the context needed for updates to state.\n\nFor example:\n```js\nimport { helloWorld } from './hello';\n\nexport const onAppMount = (message) =\u003e async ({ update, getState, dispatch }) =\u003e {\n\tupdate('app', { mounted: true });\n\tupdate('clicked', false);\n\tupdate('data', { mounted: true });\n\tawait update('', { data: { mounted: false } });\n\n\tconsole.log('getState', getState());\n\n\tupdate('foo.bar', { hello: true });\n\tupdate('foo.bar', { hello: false, goodbye: true });\n\tupdate('foo', { bar: { hello: true, goodbye: false } });\n\tupdate('foo.bar.goodbye', true);\n\n\tawait new Promise((resolve) =\u003e setTimeout(() =\u003e {\n\t\tconsole.log('getState', getState());\n\t\tresolve();\n\t}, 2000));\n\n\tdispatch(helloWorld(message));\n};\n```\n## Prefixing store and Provider\n\nThe default names the `State` factory method returns are `store` and `Provider`. However, if you want multiple stores and provider contexts you can pass an additional `prefix` argument to disambiguate.\n\n```js\nexport const { appStore, AppProvider } = State(initialState, 'app');\n```\n\n## Performance and memo\n\nThe updating of a single store, even several levels down, is quite quick. If you're worried about components re-rendering, use `memo`:\n```js\nimport React, { memo } from 'react';\n\nconst HelloMessage = memo(({ message }) =\u003e {\n\tconsole.log('rendered message');\n\treturn \u003cp\u003eHello { message }\u003c/p\u003e;\n});\n\nexport default HelloMessage;\n```\nHigher up the component hierarchy you might have:\n```js\nconst App = () =\u003e {\n\tconst { state, dispatch, update } = useContext(appStore);\n    ...\n\tconst handleClick = () =\u003e {\n\t\tupdate('clicked', !state.clicked);\n\t};\n\n\treturn (\n\t\t\u003cdiv className=\"root\"\u003e\n\t\t\t\u003cHelloMessage message={state.foo \u0026\u0026 state.foo.bar.hello} /\u003e\n\t\t\t\u003cp\u003eclicked: {JSON.stringify(state.clicked)}\u003c/p\u003e\n\t\t\t\u003cbutton onClick={handleClick}\u003eClick Me\u003c/button\u003e\n\t\t\u003c/div\u003e\n\t);\n};\n```\nWhen the button is clicked, the component HelloMessage will not re-render, it's value has been memoized (cached). Using this method you can easily prevent performance intensive state updates in further down components until they are neccessary.\n\nReference:\n- https://reactjs.org/docs/context.html\n- https://dmitripavlutin.com/use-react-memo-wisely/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhashi7412%2Fnft-staking","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhashi7412%2Fnft-staking","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhashi7412%2Fnft-staking/lists"}