Skip to content

Commit

Permalink
📝 update SNIP-3 new syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelStark committed Feb 13, 2025
1 parent 4aad86f commit 74ca8a9
Showing 1 changed file with 64 additions and 51 deletions.
115 changes: 64 additions & 51 deletions SNIPS/snip-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ Inspired by [EIP-721](https://eips.ethereum.org/EIPS/eip-721).

## Abstract

See https://eips.ethereum.org/EIPS/eip-721#abstract.
See <https://eips.ethereum.org/EIPS/eip-721#abstract>.

## Motivation

See https://eips.ethereum.org/EIPS/eip-721#motivation.
See <https://eips.ethereum.org/EIPS/eip-721#motivation>.

## Specification

### Methods

**NOTES**:
- The following specifications use syntax from Cairo `0.8.1` (or above)

- The following specifications use syntax from Cairo `2.9.2` (or above)

### balanceOf

Count all NFTs assigned to an owner.

NFTs assigned to the zero address are considered invalid, and this function throws for queries about the zero address.

``` cairo
func balanceOf(owner: felt) -> (balance: Uint256):
end
```cairo
fn balanceOf(self: @TState, account: ContractAddress) -> u256
```

### ownerOf
Expand All @@ -46,9 +46,8 @@ Find the owner of an NFT.

NFTs assigned to zero address are considered invalid, and queries about them do throw.

``` cairo
func ownerOf(tokenId: Uint256) -> (owner: felt):
end
```cairo
fn ownerOf(self: @TState, tokenId: u256) -> ContractAddress
```

### safeTransferFrom
Expand All @@ -57,89 +56,103 @@ Transfers the ownership of an NFT from one address to another address.

Throws unless `get_caller_address` is the current owner, an authorized operator, or the approved address for this NFT.

Throws if `from_` is not the current owner.

``` cairo
func safeTransferFrom(
from_: felt,
to: felt,
tokenId: Uint256,
data_len: felt,
data: felt*
):
end
Throws if `from` is not the current owner.

```cairo
fn safeTransferFrom(
ref self: TState,
from: ContractAddress,
to: ContractAddress,
tokenId: u256,
data: Span<felt252>
)
```

### transferFrom

``` cairo
func transferFrom(from_: felt, to: felt, tokenId: Uint256):
end
```cairo
fn transferFrom(ref self: TState, from: ContractAddress, to: ContractAddress, tokenId: u256)
```

### approve

``` cairo
func approve(approved: felt, tokenId: Uint256):
end
```cairo
fn approve(ref self: TState, approved: ContractAddress, tokenId: u256)
```

### setApprovalForAll

``` cairo
func setApprovalForAll(operator: felt, approved: felt):
end
```cairo
fn setApprovalForAll(ref self: TState, operator: ContractAddress, approved: bool)
```

### getApproved

``` cairo
func getApproved(tokenId: Uint256) -> (approved: felt):
end
```cairo
fn getApproved(self: @TState, tokenId: u256) -> ContractAddress
```

### isApprovedForAll

``` cairo
func isApprovedForAll(owner: felt, operator: felt) -> (isApproved: felt):
end
```cairo
fn isApprovedForAll(self: @TState, owner: ContractAddress, operator: ContractAddress) -> bool
```

### Events

#### Transfer

``` cairo
@event
func Transfer(from_: felt, to: felt, tokenId: Uint256):
end
```cairo
/// Emitted when `token_id` token is transferred from `from` to `to`.
#[derive(Drop, PartialEq, starknet::Event)]
struct Transfer {
#[key]
from: ContractAddress,
#[key]
to: ContractAddress,
#[key]
token_id: u256,
}
```

#### Approval

``` cairo
@event
func Approval(owner: felt, approved: felt, tokenId: Uint256):
end
```cairo
/// Emitted when `owner` enables `approved` to manage the `token_id` token.
#[derive(Drop, PartialEq, starknet::Event)]
struct Approval {
#[key]
owner: ContractAddress,
#[key]
approved: ContractAddress,
#[key]
token_id: u256,
}
```

#### ApprovalForAll

``` cairo
@event
func ApprovalForAll(owner: felt, operator: felt, approved: felt):
end
```cairo
/// Emitted when `owner` enables or disables (`approved`) `operator` to manage
/// all of its assets.
#[derive(Drop, PartialEq, starknet::Event)]
struct ApprovalForAll {
#[key]
owner: ContractAddress,
#[key]
operator: ContractAddress,
approved: bool,
}
```

## Implementation

#### Example implementations are available at
- [OpenZeppelin implementation](https://github.com/OpenZeppelin/cairo-contracts/tree/main/src/openzeppelin/token/erc721)
Example implementations are available at

- [OpenZeppelin implementation](https://github.com/OpenZeppelin/cairo-contracts/blob/main/packages/token/src/erc721/erc721.cairo)

## History


## Copyright

Copyright and related rights waived via [MIT](../LICENSE).
Copyright and related rights waived via [MIT](../LICENSE).

0 comments on commit 74ca8a9

Please sign in to comment.