Giter Site home page Giter Site logo

cairo-contracts's Introduction

OpenZeppelin Cairo Contracts

A library for secure smart contract development written in Cairo for StarkNet, a decentralized ZK Rollup.

⚠️ WARNING! ⚠️

This is repo contains highly experimental code. Expect rapid iteration. Do not use in production.

Quickstart

A mashup between Cairo's quickstart and StarkWare's intro.

0. Install Cairo

We recommend working inside a python virtual environment, but you can also install the Cairo package directly. To create and enter the virtual environment, type:

python3.7 -m venv ~/cairo_venv
source ~/cairo_venv/bin/activate

Make sure the venv is activated – you should see (cairo_venv) in the command line prompt.

Make sure you can install the following pip packages: ecdsa, fastecdsa, sympy (using pip3 install ecdsa fastecdsa sympy). On Ubuntu, for example, you will have to first run:

sudo apt install -y libgmp3-dev

On Mac, you can use brew:

brew install gmp

Download the python package (cairo-lang-0.3.1.zip) from https://github.com/starkware-libs/cairo-lang/releases/tag/v0.3.1. To install it using pip, run:

pip3 install cairo-lang-0.3.1.zip

Cairo was tested with python3.7. To make it work with python3.6, you will have to install contextvars:

pip3 install contextvars

1. Clone the repo

git clone [email protected]:OpenZeppelin/cairo-contracts.git

Then cd into it and create a build directory:

cd cairo-contracts/
mkdir build

2. Compile the contracts

starknet-compile contracts/contract.cairo \
    --output build/contract_compiled.json \
    --abi build/contract_abi.json

3. Deploy to testnet

export STARKNET_NETWORK=alpha
starknet deploy --contract build/contract_compiled.json

4. Interact with it

starknet invoke \
    --address CONTRACT_ADDRESS \
    --abi build/contract_abi.json \
    --function increase_balance \
    --inputs 1234

The result should look like:

Invoke transaction was sent.
Contract address: 0x039564c4f6d9f45a963a6dc8cf32737f0d51a08e446304626173fd838bd70e1c
Transaction ID: 1

The following command allows you to query the transaction status based on the transaction ID that you got (here you’ll have to replace TRANSACTION_ID with the transaction ID printed by starknet invoke):

starknet tx_status --id TRANSACTION_ID

The possible statuses are:

  • NOT_RECEIVED: The transaction has not been received yet (i.e., not written to storage).
  • RECEIVED: The transaction was received by the operator.
  • PENDING: The transaction passed the validation and is waiting to be sent on-chain.
  • REJECTED: The transaction failed validation and thus was skipped.
  • ACCEPTED_ONCHAIN: The transaction was accepted on-chain.

Then we can query the balance:

starknet call \
    --address CONTRACT_ADDRESS \
    --abi build/contract_abi.json \
    --function get_balance

License

OpenZeppelin Cairo Contracts is released under the MIT License.

cairo-contracts's People

Contributors

martriay avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.