Skip to content

A collection of smart contracts written in Cairo 1.0 (Starknet)

Notifications You must be signed in to change notification settings

BlockchainAsset/cairo-contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Cairo Contracts

A collection of smart contracts written in Cairo 1.0 (Starknet).

Code, Class Hash & Contracts

Contract Name Cairo Code Cairo Test Class Hash Testnet Contract
Broadcast broadcast.cairo 0x4597....53ea 0x06c7....bc44
Splitter splitter.cairo test_splitter.cairo 0x3dfd....3221 0x004d....7097
GetPedersen get_pedersen.cairo test_get_pedersen.cairo 0x7e02....f036 0x0534....5679

Requirements

The contract should be compiled with latest version of CAIRO which can be found here.

Installing & Creating Account

Please follow this video: https://www.youtube.com/watch?v=NdP2jTQ34hY

Or the repo: https://github.com/starknet-edu/deploy-cairo1-demo

Old Account

If you already have an account, then you can simply add the private_key, address and mark deployed to be true in ./starknet_accounts/starknet_open_zeppelin_accounts.json or in similarly named files in that folder.

NOTE: Using an old account, might lead to StarknetErrorCode.ENTRY_POINT_NOT_FOUND_IN_CONTRACT error. In those cases, creating a fresh account, and transferring some ETH from old account to the new one is advised.

Testing

To run the tests for this contract, you should run cairo-test --starknet --path . in the git root directory (the directory which has cairo-project.toml).

The above command only works if you have added the PATH. If not, you have to run from the installed Cairo repository:

cargo run --bin cairo-test -- --starknet --path ./specify/path/to/this/repo

Deployment

You can deploy the contracts in the src folder as mentioned below.

Compilation

To store the compiled contracts, we have created a compiled folder in root.

Then, you can use the below command to compile from CAIRO to Sierra:

starknet-compile ./src/FILENAME.cairo ./compiled/FILENAME.json --replace-ids

If you didn't specified CAIRO in PATH, you can use the below command within the cairo folder:

cargo run --bin starknet-compile -- ./src/FILENAME.cairo ./compiled/FILENAME.json --replace-ids

Contract Declaration

Now, it's time to declare the contract.

starknet declare --contract compiled/filename.json --account version11.0

You can expect a response like this:

Sending the transaction with max_fee: 0.000XXX ETH (XXX WEI).
Declare transaction was sent.
Contract class hash: 0x...
Transaction hash: 0x...

NOTE: If you are declaring the same contract, then you will run into an error, as the class hash is already declated.

Contract Deployment

Now to deploy a contract, use the below command:

starknet deploy --class_hash <class_hash> --account version11.0

The <class_hash> is the class hash taken from the output of declare command.

Disclaimer

This is for learning, not for production. And as CAIRO is improving each day, some of the code may not work after some time due to those changes.

Inspiration

https://github.com/starknet-edu/deploy-cairo1-demo

https://github.com/Kalzak/RockPaperScissors-Cairo

https://github.com/shramee/starklings-cairo1

https://www.youtube.com/watch?v=NdP2jTQ34hY

About

A collection of smart contracts written in Cairo 1.0 (Starknet)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages