{"id":13544100,"url":"https://github.com/OffchainLabs/stylus-workshop-rust-solidity","last_synced_at":"2025-04-02T14:30:23.520Z","repository":{"id":226788545,"uuid":"769146850","full_name":"OffchainLabs/stylus-workshop-rust-solidity","owner":"OffchainLabs","description":"Stylus workshop for interaction between Rust and Solidity","archived":false,"fork":false,"pushed_at":"2024-10-07T11:50:33.000Z","size":183,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-17T21:45:56.145Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Solidity","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/OffchainLabs.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-08T12:47:40.000Z","updated_at":"2025-01-25T04:55:04.000Z","dependencies_parsed_at":"2024-06-06T15:47:30.529Z","dependency_job_id":"b4418ab9-58df-4ddb-ab96-2bdc23017210","html_url":"https://github.com/OffchainLabs/stylus-workshop-rust-solidity","commit_stats":null,"previous_names":["offchainlabs/stylus-workshop-rust-solidity"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OffchainLabs%2Fstylus-workshop-rust-solidity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OffchainLabs%2Fstylus-workshop-rust-solidity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OffchainLabs%2Fstylus-workshop-rust-solidity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OffchainLabs%2Fstylus-workshop-rust-solidity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OffchainLabs","download_url":"https://codeload.github.com/OffchainLabs/stylus-workshop-rust-solidity/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246832043,"owners_count":20841096,"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-08-01T11:00:42.061Z","updated_at":"2025-04-02T14:30:23.190Z","avatar_url":"https://github.com/OffchainLabs.png","language":"Solidity","funding_links":[],"categories":["Examples"],"sub_categories":["Examples built with cargo-stylus v0.4.x and stylus-sdk v0.5.x"],"readme":"# Stylus workshop (Rust \u0026 Solidity)\n\nThis repo contains an example of 3 contracts (an ERC-721 contract and an Art contract both written in Rust, and an ERC-20 contract written in Solidity) interacting with each other.\n\nThe ERC-721 contract contains a basic Rust implementation of the standard, which calls the external Art contract to generate the image when invoking the `tokenURI` method.\n\nThe Art contract contains a Rust implementation of a basic generative art algorithm that draws an image with different colors depending on the address and the token id being passed as inputs. It is based on the [Stylus workshop NFT](https://github.com/OffchainLabs/stylus-workshop-nft/) implementation.\n\nThe ERC-20 contract contains a basic Solidity implementation of the standard. It is based on OpenZeppelin's implementation.\n\n## Interactions between contracts\n\nThe three contracts interact with each other in the following way:\n- On ERC-721 initialization, both Art and ERC-20 contracts are also initialize by invoking the respective `initialize` methods. \n- When the `tokenURI()` method of the ERC-721 contract is invoked, this contract calls method `generate_art` of the Art contract, passing both a `tokenId` and the `owner` of that token.\n- When the `generate_art` method of the Art contract is invoked with only a `tokenId` as input, the Art contract calls method `ownerOf` of the ERC-721 contract to obtain the owner of such token.\n- When a user tries to mint an NFT the owner must have a minimum balance of ERC-20 tokens. Thus, the `mint` method also invokes the `balanceOf` method of the ERC-20 contract for the minter.\n- A user can also try to mint an NFT from the ERC-20 contract, by invoking the method `mintNft()`. This method will call method `mint` of the NFT contract.\n\n## Getting started\n\nFollow the instructions in the [Stylus quickstart](https://docs.arbitrum.io/stylus/stylus-quickstart) to configure your development environment.\n\nYou'll also need [Foundry](https://github.com/foundry-rs/foundry) to build and deploy the ERC-20 contract.\n\n## Project structure\n\nClone the project\n\n```sh\ngit clone https://github.com/OffchainLabs/stylus-workshop-rust-solidity.git\ncd stylus-workshop-rust-solidity\n```\n\nThere are four directories inside:\n\n- **nft**: contains the Stylus project for the ERC-721 contract\n- **art**: contains the Stylus project for the Art contract\n- **erc20**: contains the Foundry project for the ERC-20 contract \n\n## Deploy your contracts\n\nRust and Solidity contracts are built and deployed differently.\n\n### Rust contracts\n\nFor Rust projects, access the project folder and build and deploy the contract using the `cargo stylus` tool. Following is an example for the Art contract.\n\nAccess the `art` folder\n\n```sh\ncd art\n```\n\nRun the check tool\n\n```sh\ncargo stylus check\n```\n\nDeploy the contract\n\n```sh\ncargo stylus deploy -e $YOUR_RPC_URL --private-key $YOUR_PRIVATE_KEY\n```\n\nNote that it's generally better to use `--private-key-path` for security reasons.\n\nSee `cargo stylus deploy --help` for more information.\n\n### Solidity contract\n\nAccess the `erc20` folder\n\n```sh\ncd erc20\n```\n\nBuild the project\n\n```sh\nforge build\n```\n\nDeploy it\n\n```sh\nforge create --rpc-url $YOUR_RPC_URL --private-key $YOUR_PRIVATE_KEY src/MyToken.sol:MyToken\n```\n\nSee `forge create --help` for more information.\n\n## Test script\n\nYou can use the following flow for the most important actions:\n\n1. Create a copy (`.env`) and update the environment variables on [./scripts/.env.example](./scripts/.env.example)\n2. [./scripts/1-deploy.sh](./scripts/1-deploy.sh) to deploy all contracts\n3. Export all contract addresses in environment variables: ART_CONTRACT_ADDRESS, NFT_CONTRACT_ADDRESS, ERC20_CONTRACT_ADDRESS\n4. [./scripts/2-initialize.sh](./scripts/2-initialize.sh) to initialize the contracts\n5. [./scripts/mintTokens.sh](./scripts/mintTokens.sh) to mint some ERC-20 tokens\n6. [./scripts/mintNft.sh](./scripts/mintNft.sh) to mint an NFT\n7. [./scripts/getBalance.sh](./scripts/getBalance.sh) to obtain the balance of the minter\n8. [./scripts/getTokenImage.sh](./scripts/getTokenImage.sh) to get the image generated for tokenId 0\n9. [./scripts/transferNft.sh](./scripts/transferNft.sh) to transfer the NFT 0 from the minter to the RECEIVER\n10. [./scripts/mintNftFromTokenContract.sh](./scripts/mintNftFromTokenContract.sh) to mint an NFT from the ERC-20 contract\n\n## How to run a local dev node\n\nInstructions to setup a local dev node can be found [here](https://docs.arbitrum.io/run-arbitrum-node/run-local-dev-node).\n\n## Useful resources\n\n- [Stylus quickstart](https://docs.arbitrum.io/stylus/stylus-quickstart)\n- [Stylus by example](https://stylus-by-example.org/)\n- [Awesome Stylus](https://github.com/OffchainLabs/awesome-stylus)\n- [Counter contract](https://github.com/OffchainLabs/stylus-workshop-counter)\n- [Interactions between Rust and Solidity](https://github.com/OffchainLabs/stylus-workshop-rust-solidity/)\n- [Presentation slides](https://docs.google.com/presentation/d/e/2PACX-1vQB44hpWHBig5REVntjxK-Djs8p1XuQB26pg0ouldTWxTaaYpK3awEV4A8Spv9Z3nCr-473ix853sbr/pub?start=false\u0026loop=false\u0026delayms=3000)\n- [Telegram group](https://t.me/arbitrum_stylus)\n- [Discord channel](https://discord.com/channels/585084330037084172/1146789176939909251)\n\n## Stylus reference links\n\n- [Stylus documentation](https://docs.arbitrum.io/stylus/stylus-gentle-introduction)\n- [Stylus SDK](https://github.com/OffchainLabs/stylus-sdk-rs)\n- [Cargo Stylus](https://github.com/OffchainLabs/cargo-stylus)\n\n## Disclaimer\n\nThis code has **not** been audited and should **not** be used in a production environment.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOffchainLabs%2Fstylus-workshop-rust-solidity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FOffchainLabs%2Fstylus-workshop-rust-solidity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOffchainLabs%2Fstylus-workshop-rust-solidity/lists"}