GithubHelp home page GithubHelp logo

apeworx / archive-ape-cairo Goto Github PK

View Code? Open in Web Editor NEW
8.0 4.0 6.0 133 KB

Cairo programming language compiler plugin for the Ape Framework

Home Page: https://www.apeworx.io/

License: Apache License 2.0

Python 87.12% Cairo 12.88%
python cairo starknet web3 smart-contracts cairo-lang ape apeworx starknet-ecosystem starknet-foundation

archive-ape-cairo's Introduction

Quick Start

Ape compiler plugin around the Cairo language.

Dependencies

Installation

via pip

You can install the latest release via pip:

pip install ape-cairo

via setuptools

You can clone the repository and use setuptools for the most up-to-date version:

git clone https://github.com/ApeWorX/ape-cairo.git
cd ape-cairo
python3 setup.py install

Quick Usage

First, you will need to tell ape-cairo how to use the Cairo compiler. There are two ways to do this:

  1. Configure your Cairo manifest path in your ape-config.yaml.
  2. Build or add Cairo compiler binaries to your $PATH.

Both options require cloning the Cairo compiler source code:

git clone [email protected]:starkware-libs/cairo.git
cd cairo
git fetch --all
git checkout <tag>  # e.g. v1.0.0-alpha.6

To do the first option, add the following to your ape-config.yaml file:

cairo:
  manifest: /Users/home/path/to/cairo/Cargo.toml

Now, when compiling, Ape will use the command cargo run --bin <BIN> --manifest-path <CAIRO-MANIFEST>. To do the second option instead, build the release binaries for your OS:

cargo build --release

NOTE: This requires being in the same directory as Cairo.

After the build completes, add the target path to your global $PATH variable. (You may want to add this to your .zshrc / .bashrc file):

export PATH=$PATH:$HOME/path/to/cairo/target/release

Verify you have sierra-compile in your $PATH by doing:

which sierra-compile

WARN: Note that when using Cairo-lang the python package, it will add conflicting binaries with the same name. You will need to ensure you are using the correct binaries if you have cairo-lang the Python package installed.

which starknet-compile

Alternatively, the first approach avoids this problem.

Using the Compiler

In a project directory where there are .cairo files in your contracts/ directory, run the compile command:

ape compile

It should create ContractType objects in your .build/ folder containing the necessary Sierra code for contract declaration.

Development

This project is in development and should be considered a beta. Things might not be in their final state and breaking changes may occur. Comments, questions, criticisms and pull requests are welcomed.

archive-ape-cairo's People

Contributors

0xlucqs avatar antazoey avatar ca11ab1e avatar dtdang avatar notpeopling2day avatar tserg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

archive-ape-cairo's Issues

Create custom `ContractType` to override selector fn to use `starknet_keccak`

Overview

Currently, we cannot access methods the nice way using the keccak selectors with contract types from Cairo.
We should make a custom StarknetContractType in the compiler with its own selector method so the ape-starknet plugin can load method ABIs when its is re-serializing transactions.

Specification

StarknetContractType(ContractType):
  _selector_hash_fn = starknet_keccak

Dependencies

Include links to any open issues that must be resolved before this feature can be implemented.

need better way to describe contract type names other than file name

Environment information

It is very common for complicated libraries to use the file name library.cairo across various paths.
Currently, we are only looking at the file name as the contract type.

What went wrong?

When trying to compile https://github.com/OpenZeppelin/cairo-contracts, I get:

ERROR: (CompilerError) ContractType collision across compiler plugins with contract name: library

How can it be fixed?

Use the full . path to the file (include the namespace).

E.g.

src/openzeppelin/accounts/library.cairo should have the contract type name of accounts.library

where the contracts folder is set as src/openzeppelin

Using ape cli returns : ModuleNotFoundError: No module named 'starknet_py.utils.compiler'

Environment information

  • ape and plugin versions:
$ ape --version
0.2.2
$ ape plugins list
Installed Plugins:
cairo       0.2.0a1

  • Python Version: 3.8.10
  • OS: ubuntu 20.04

What went wrong?

Whenever I try to use any ape command I get an error from the cairo plugin which says:

$ ape init
WARNING: Error loading plugin package 'ape_cairo'.
	ModuleNotFoundError: No module named 'starknet_py.utils.compiler'
	(Use `--verbosity DEBUG` to see full stack-trace)

How can it be fixed?

Can be fixed by changing the requirements from starknet.py

Issue compiling Account contracts

Environment information

ape compile

starkware.cairo.lang.compiler.preprocessor.preprocessor_error.PreprocessorError: Only account contracts may have a function named "execute". Use --account_contract flag.

Seems like an extra flag is needed in the compiler?

What went wrong?

Please include information like:

  • what command you ran
  • the code that caused the failure (see this link for help with formatting code)
  • full output of the error you received

How can it be fixed?

Fill this in if you have ideas on how the bug could be fixed.

Allow using dependencies

Overview

Allow the user to import their cairo dependencies in their cairo smart-contract

Specification

If the user has specified dependencies like this:

dependencies:
  - name: OpenZeppelin
    github: OpenZeppelin/cairo-contracts
    version: 0.1.0
    contracts_folder: src

Allow them to import those dependencies in like this:

from openzeppelin.utils.constants import INVALID_ID, IERC165_ID

Remember, your feature is much more likely to be included if it does not involve any breaking changes.

Dependencies

Include links to any open issues that must be resolved before this feature can be implemented.

Feat: warp version error #1098 [APE-1576]

To resolve the error encountered when installing @nethermindeth/warp on a Mac M1, update Node.js and Yarn to the latest versions, reinstall dependencies with yarn global upgrade and yarn global remove/add, ensure StarkNet is properly installed, check and adjust the system's PATH variable for StarkNet, verify compatibility with Mac M1 architecture, and consult the official documentation and community forums for both StarkNet and @nethermindeth/warp for potential solutions.

Cairo 0.9.0 support

As shown in #16:

WARNING: Error loading plugin package 'ape_cairo'.
	ModuleNotFoundError: No module named 'starkware.starknet.services.api.contract_definition'

The code needs to be updated in order to support Cairo 0.9.0.

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.