Skip to content

Conversation

@ericglau
Copy link
Member

@ericglau ericglau commented Jan 11, 2023

Fixes #216

This follows the general Contracts for Cairo format, with slight differences for more consistency between different functions.

  • Keeps implicit args on the same line as the function name
  • If there are args, use a separate line for args, then another line for return types e.g.
func balanceOf{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
    account: felt, id: Uint256
) -> (balance: Uint256) {
  • If args line is too long, wraps it as one arg per line:
func safeBatchTransferFrom{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
    from_: felt,
    to: felt,
    ids_len: felt,
    ids: Uint256*,
    values_len: felt,
    values: Uint256*,
    data_len: felt,
    data: felt*,
) {
  • If there are no args, keep return type on the same line as function name e.g.
func name{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (name: felt) {

@ericglau ericglau requested a review from frangio January 11, 2023 19:02
Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

ericglau and others added 2 commits January 11, 2023 16:10
@ericglau ericglau merged commit 972d9ee into OpenZeppelin:master Jan 11, 2023
@ericglau ericglau deleted the cairo-formatting branch January 11, 2023 21:40
@github-actions github-actions bot mentioned this pull request Jun 20, 2025
@github-actions github-actions bot mentioned this pull request Aug 20, 2025
This was referenced Sep 9, 2025
@github-actions github-actions bot mentioned this pull request Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Cairo formatting

2 participants