Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/satyambnsal/cairo-smart-contracts
Smart contracts written in Cairo
https://github.com/satyambnsal/cairo-smart-contracts
Last synced: 2 days ago
JSON representation
Smart contracts written in Cairo
- Host: GitHub
- URL: https://github.com/satyambnsal/cairo-smart-contracts
- Owner: satyambnsal
- License: mit
- Created: 2023-08-16T10:58:15.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-05T09:54:19.000Z (7 months ago)
- Last Synced: 2024-04-20T08:57:22.246Z (7 months ago)
- Language: Cairo
- Size: 90.8 KB
- Stars: 5
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Cairo Smart contracts
Smart contracts written in cairo1.0### Important Commands
Install rust
```
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```Check rust version
```
rustc --version
```Install scarb
```
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh
```Check scarb version
```
scarb --version
```
Install **starkli**
```
curl https://get.starkli.sh | sh
starkliup
```Check **starkli** version
```
starkli --version
```
# Local Deployment With KatanaInstall Katana
```
git clone https://github.com/dojoengine/dojo
cd dojo
cargo install --path ./crates/katana --locked --force
```## How to Generate a keystore and account descriptor for Local development
1. Start katana with `katana` command. You should see a list of accounts with **Account Address**, **Private Key**, and **Public Key**
and see similar message 👇
```
🚀 JSON-RPC server started: http://0.0.0.0:5050
```2. Create a keystore file by running
```
starkli signer keystore from-key ~/.starkli-wallets/deployer/my_local_account_1_key.json
```
Note: If you see folder not found or similar error, create `.starkli-wallets/deployer` folder with `mkdir`Now, you should see a prompt asking for a **Private Key**. copy first account private key from katana output.
Now. you see a prompt asking for a password. remember to enter something you can remember easily 😀
that's it, now we have our keystore file.3. Create account descriptor file
```
touch ~/.starkli-wallets/deployer/my_local_account_1.json
```
Open the newly created `my_local_account_1.json` file and paste following content
```
{
"version": 1,
"variant": {
"type": "open_zeppelin",
"version": 1,
"public_key": ""
},
"deployment": {
"status": "deployed",
"class_hash": "",
"address": ""
}
}
```- here replace **** and **** with respected values that you have from `katana` command output.
- to get a class hash for wallet run, replace **SMART_WALLET_ADDRESS** with respected value.
```
starkli class-hash-at --rpc http://0.0.0.0:5050
```
You will get class hash as the output, put that value in `my_local_account_1.json` file.## How to setup Katana wallet and rpc file path.
Replace respected file path in `local.env` file and then run `source local.env` on terminal. you can verify if values are set correctly using
```
echo ${STARKNET_ACCOUNT}
```# Testnet deployment with Goerli Network and Braavos Wallet
1. Copy your Braavos wallet private key from **Privacy and Security section**
![Braavos Private Key](/assets/braavos_private_key.png)
2. Create a keystore file for starkli
```
starkli signer keystore from-key ~/.starkli-wallets/deployer/my_testnet_account_1_key.json
```
Note: If you see folder not found or similar error, create `.starkli-wallets/deployer` folder with `mkdir`3. Create a account descriptor
```
account fetch --output ~/.starkli-wallets/deployer/my_testnet_account_1.json
```
Here Replace with your Braavos wallet address.
You Should see a message similar to
```
WARNING: no valid provider option found. Falling back to using the sequencer gateway for the goerli-1 network. Doing this is discouraged. See https://book.starkli.rs/providers for more details.
Account contract type identified as: Braavos
Description: Braavos official proxy account
Downloaded new account config file: ~/.starkli-wallets/deployer/my_testnet_account_1.json
```
Note: If you get unknown class hash error, checkout [Issues](#Known-Issues) section.4. Create a new env file `testnet.env` and copy `sample.testnet.env` content. You can replace values if you are using different RPC or path for keys is different.
5. run `source testnet.env` to export env variables to your terminal. you can verify if values are set correctly using
```
echo ${STARKNET_ACCOUNT}
```# How to declare contract
```
starkli declare target/dev/.sierra.json --compiler-version 2.1.0
```# How to deploy contract
```
starkli deploy
```# How to call contract methods
1. To call view functions, use **call** keyword, for example
```
starkli call 0x03d568de0f4e151ed97a196e7585cae03be68b8d01c3d5af2e19c7aa4bb07202 get
```2. To call writable functions, use **invoke** keyword, for example
```
starkli invoke 0x03d568de0f4e151ed97a196e7585cae03be68b8d01c3d5af2e19c7aa4bb07202 set 7
```## Important Facts
- In Cairo, a string is a collection of characters stored in a `felt252`. Strings can have a maximum length of 31 characters.
- field elements are integers in the range between `0 <= x < P`, where P is a very large prime number, currently `P = 2^{251} + 17 * 2^{192} + 1`# Known-Issues
1. **Unknown Classhash error**:
If you get an unknown classhash error while creating account descriptor for your braavos account, you can create a account file manually.
create a file `~/.starkli-wallets/deployer/my_testnet_account1.json` with following content
```
{
"version": 1,
"variant": {
"type": "open_zeppelin",
"version": 1,
"public_key": ""
},
"deployment": {
"status": "deployed",
"class_hash": "",
"address": ""
}
}
```- Get ****, from **Privacy and Security** section in **Braavos**
- To get classhash, open `https://testnet.starkscan.co/contract/` link in browser. you should be able to see classhash for your account.# Starknet foundry commands
Declare a contract
```
sncast --profile declare --contract-name```
Deploy a contract
```
sncast --profile testnet1 deploy --class-hash --constructor-calldata 10000000000 0 0x032aee2a95f251a984a391fb2919757a9074065f3c12b010a142c9fd939e933
```# Other Useful commands
1. Run `scarb --offline build` to build a project without updating dependencies.
## Important Links
- [Braavos google play store link](https://chrome.google.com/webstore/detail/braavos-smart-wallet/jnlgamecbpmbajjfhmmmlhejkemejdma)
- [Starknet Goerli network faucet](https://faucet.goerli.starknet.io)
- [Starscan](https://testnet.starkscan.co/)
- [Voyager](https://goerli.voyager.online/?lang=en-US&theme=light)
- [Starknet Documentation](https://docs.starknet.io/documentation/)
- [Starknet Book](https://book.starknet.io/)
- [Cairo Book](https://cairo-book.github.io/)
- [Starknet Foundry book](https://foundry-rs.github.io/)
- [Starknet Ecosystem](https://www.starknet-ecosystem.com/)
- [Run Starknet Locally with Katana](https://book.dojoengine.org/toolchain/katana/overview.html)
- [Starknet By Example Voyager book](https://starknet-by-example.voyager.online/)
- [Starknet Converter Utility](https://www.stark-utils.xyz/converter)
- [Starknet docs](https://docs.starknet.io/)