Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

grc721 source pure

Constants 2

Variables 1

var ErrInvalidTokenId, ErrInvalidAddress, ErrTokenIdNotHasApproved, ErrApprovalToCurrentOwner, ErrCallerIsNotOwner, ErrCallerNotApprovedForAll, ErrCannotTransferToSelf, ErrTransferFromIncorrectOwner, ErrTransferToNonGRC721Receiver, ErrCallerIsNotOwnerOrApproved, ErrTokenIdAlreadyExists, ErrSpoofedRealm, ErrNotRealm, ErrInvalidName, ErrInvalidSymbol, ErrInvalidRoyaltyPercentage, ErrInvalidRoyaltyPaymentAddress, ErrCannotCalculateRoyaltyAmount

 1var (
 2	ErrInvalidTokenId              = errors.New("invalid token id")
 3	ErrInvalidAddress              = errors.New("invalid address")
 4	ErrTokenIdNotHasApproved       = errors.New("token id not approved for anyone")
 5	ErrApprovalToCurrentOwner      = errors.New("approval to current owner")
 6	ErrCallerIsNotOwner            = errors.New("caller is not token owner")
 7	ErrCallerNotApprovedForAll     = errors.New("caller is not approved for all")
 8	ErrCannotTransferToSelf        = errors.New("cannot send transfer to self")
 9	ErrTransferFromIncorrectOwner  = errors.New("transfer from incorrect owner")
10	ErrTransferToNonGRC721Receiver = errors.New("transfer to non GRC721Receiver implementer")
11	ErrCallerIsNotOwnerOrApproved  = errors.New("caller is not token owner or approved")
12	ErrTokenIdAlreadyExists        = errors.New("token id already exists")
13
14	// NewBasicNFT realm binding
15	ErrSpoofedRealm  = errors.New("rlm does not match the current crossing frame")
16	ErrNotRealm      = errors.New("rlm must be a realm (got EOA/origin)")
17	ErrInvalidName   = errors.New("invalid token name (empty, too long, or contains control chars)")
18	ErrInvalidSymbol = errors.New("invalid token symbol (empty, too long, or contains chars outside [A-Za-z0-9_-])")
19
20	// ERC721Royalty
21	ErrInvalidRoyaltyPercentage     = errors.New("invalid royalty percentage")
22	ErrInvalidRoyaltyPaymentAddress = errors.New("invalid royalty paymentAddress")
23	ErrCannotCalculateRoyaltyAmount = errors.New("cannot calculate royalty amount")
24)
source

Functions 3

func NewBasicNFT

1func NewBasicNFT(_ int, rlm realm, name, symbol string) *BasicNFT
source

func NewNFTWithMetadata

1func NewNFTWithMetadata(_ int, rlm realm, name, symbol string) *metadataNFT
source

NewNFTWithMetadata creates a new basic NFT with metadata extensions.

func NewNFTWithRoyalty

1func NewNFTWithRoyalty(_ int, rlm realm, name, symbol string) *royaltyNFT
source

NewNFTWithRoyalty creates a new royalty NFT with the specified name, symbol, and royalty calculator.

Types 12

type BasicNFT

struct
 1type BasicNFT struct {
 2	name              string
 3	symbol            string
 4	origRealm         string   // owning realm's package path
 5	owners            avl.Tree // tokenId -> OwnerAddress
 6	balances          avl.Tree // OwnerAddress -> TokenCount
 7	tokenApprovals    avl.Tree // TokenId -> ApprovedAddress
 8	tokenURIs         avl.Tree // TokenId -> URIs
 9	operatorApprovals avl.Tree // "OwnerAddress:OperatorAddress" -> bool
10}
source

Methods on BasicNFT

func Approve

method on BasicNFT
1func (s *BasicNFT) Approve(caller, to address, tid TokenID) error
source

Approve approves the input address for a particular token. caller must be the owner OR an operator approved for all on owner's behalf. The owning realm's wrapper validates IsCurrent and derives caller from rlm.Previous().Address() before calling.

func BalanceOf

method on BasicNFT
1func (s *BasicNFT) BalanceOf(addr address) (int64, error)
source

BalanceOf returns balance of input address

func Burn

method on BasicNFT
1func (s *BasicNFT) Burn(tid TokenID) error
source

func GetApproved

method on BasicNFT
1func (s *BasicNFT) GetApproved(tid TokenID) (address, error)
source

GetApproved return the approved address for token

func Getter

method on BasicNFT
1func (n *BasicNFT) Getter() NFTGetter
source

Getter returns an NFTGetter that yields a reader-only view of the NFT. Safe to register with cross-realm aggregators like tokenhub — readers only, no rlm-typed methods, so no cur can be captured via this surface.

func ID

method on BasicNFT
1func (s *BasicNFT) ID() string
source

func IsApprovedForAll

method on BasicNFT
1func (s *BasicNFT) IsApprovedForAll(owner, operator address) bool
source

IsApprovedForAll returns true if operator is approved for all by the owner. Otherwise, returns false

func Mint

method on BasicNFT
1func (s *BasicNFT) Mint(to address, tid TokenID) error
source

Mints `tokenId` and transfers it to `to`.

func Name

method on BasicNFT
1func (s *BasicNFT) Name() string
source

func OwnerOf

method on BasicNFT
1func (s *BasicNFT) OwnerOf(tid TokenID) (address, error)
source

OwnerOf returns owner of input token id

func RenderHome

method on BasicNFT
1func (s *BasicNFT) RenderHome() (str string)
source

func SafeMint

method on BasicNFT
1func (s *BasicNFT) SafeMint(to address, tid TokenID) error
source

Mints `tokenId` and transfers it to `to`. Also checks that contract recipients are using GRC721 protocol

func SafeTransferFrom

method on BasicNFT
1func (s *BasicNFT) SafeTransferFrom(caller, from, to address, tid TokenID) error
source

SafeTransferFrom transfers a token from `from` to `to`, checking that contract recipients are aware of the GRC721 protocol to prevent tokens from being forever locked. caller must be the owner or an approved operator. The owning realm's wrapper derives caller from rlm.Previous().Address() under an IsCurrent() guard.

func SetApprovalForAll

method on BasicNFT
1func (s *BasicNFT) SetApprovalForAll(caller, operator address, approved bool) error
source

SetApprovalForAll grants/revokes operator permission across all of the caller's tokens. caller is the owner whose approvals are mutated; the owning realm's wrapper derives it from rlm.Previous().Address() under an IsCurrent() guard.

func SetTokenURI

method on BasicNFT
1func (s *BasicNFT) SetTokenURI(caller address, tid TokenID, tURI TokenURI) (bool, error)
source

SetTokenURI sets the URI of a token. caller must equal the token's owner. The owning realm's public wrapper is responsible for deriving caller from rlm.Previous().Address() under an rlm.IsCurrent() guard before invoking this method; this method trusts the supplied caller.

func Symbol

method on BasicNFT
1func (s *BasicNFT) Symbol() string
source

func TokenCount

method on BasicNFT
1func (s *BasicNFT) TokenCount() int64
source

func TokenURI

method on BasicNFT
1func (s *BasicNFT) TokenURI(tid TokenID) (string, error)
source

TokenURI returns the URI of input token id

func TransferFrom

method on BasicNFT
1func (s *BasicNFT) TransferFrom(caller, from, to address, tid TokenID) error
source

TransferFrom transfers a token from `from` to `to`. Same caller contract as SafeTransferFrom.

type IGRC2981

interface
1type IGRC2981 interface {
2	// RoyaltyInfo retrieves royalty information for a tokenID and salePrice.
3	// It returns the payment address, royalty amount, and an error if any.
4	RoyaltyInfo(tokenID TokenID, salePrice int64) (address, int64, error)
5}
source

IGRC2981 follows the Ethereum standard

type IGRC721CollectionMetadata

interface
1type IGRC721CollectionMetadata interface {
2	Name() string   // Name returns the name of the collection.
3	Symbol() string // Symbol returns the symbol of the collection.
4}
source

IGRC721CollectionMetadata describes basic information about an NFT collection.

type IGRC721Metadata

interface
1type IGRC721Metadata interface {
2	IGRC721CollectionMetadata
3	TokenURI(tid TokenID) (string, error) // TokenURI returns the URI of a specific token.
4}
source

IGRC721Metadata follows the Ethereum standard

type IGRC721MetadataOnchain

interface
1type IGRC721MetadataOnchain interface {
2	IGRC721CollectionMetadata
3	TokenMetadata(tid TokenID) (Metadata, error)
4}
source

IGRC721Metadata follows the OpenSea metadata standard

type IGRC721Reader

interface
1type IGRC721Reader interface {
2	Name() string
3	Symbol() string
4	TokenCount() int64
5	BalanceOf(owner address) (int64, error)
6	OwnerOf(tid TokenID) (address, error)
7	GetApproved(tid TokenID) (address, error)
8	IsApprovedForAll(owner, operator address) bool
9}
source

IGRC721Reader is the read-only view of an NFT. Safe to receive across realm boundaries — has no rlm-typed methods, so a malicious impl can only lie about read results (data-integrity issue), not capture cur.

Writes are concrete methods on *BasicNFT / *metadataNFT / *royaltyNFT only — there is no IGRC721 writer interface. The owning realm should hold the concrete *BasicNFT in an unexported package var and expose public rlm-validating wrappers like:

Example
1func TransferFrom(cur realm, from, to address, tid TokenID) error {
2	caller := cur.Previous().Address()
3	return nft.TransferFrom(caller, from, to, tid)
4}

This is the Reader/Writer split — stronger than the Authority-pattern because the writer interface doesn't exist at all, so no realm author can accidentally expose it. See `r/demo/foo721` for the canonical wrapper pattern.

type Metadata

struct
 1type Metadata struct {
 2	Image           string  // URL to the image of the item. Can be any type of image (including SVGs, which will be cached into PNGs by OpenSea), IPFS or Arweave URLs or paths. We recommend using a minimum 3000 x 3000 image.
 3	ImageData       string  // Raw SVG image data, if you want to generate images on the fly (not recommended). Only use this if you're not including the image parameter.
 4	ExternalURL     string  // URL that will appear below the asset's image on OpenSea and will allow users to leave OpenSea and view the item on your site.
 5	Description     string  // Human-readable description of the item. Markdown is supported.
 6	Name            string  // Name of the item.
 7	Attributes      []Trait // Attributes for the item, which will show up on the OpenSea page for the item.
 8	BackgroundColor string  // Background color of the item on OpenSea. Must be a six-character hexadecimal without a pre-pended #
 9	AnimationURL    string  // URL to a multimedia attachment for the item. Supported file extensions: GLTF, GLB, WEBM, MP4, M4V, OGV, OGG, MP3, WAV, OGA, HTML (for rich experiences and interactive NFTs using JavaScript canvas, WebGL, etc.). Scripts and relative paths within the HTML page are now supported. Access to browser extensions is not supported.
10	YoutubeURL      string  // URL to a YouTube video (only used if animation_url is not provided).
11}
source

type NFTGetter

func
1type NFTGetter func() IGRC721Reader
source

NFTGetter returns a reader-only view of an NFT. Aggregators (such as tokenhub) register and dispatch NFTGetters; the reader-only return type means even a malicious aggregator can't be used to leak cur.

type RoyaltyInfo

struct
1type RoyaltyInfo struct {
2	PaymentAddress address // PaymentAddress is the address where royalty payment should be sent.
3	Percentage     int64   // Percentage is the royalty percentage. It indicates the percentage of royalty to be paid for each sale. For example : Percentage = 10 => 10%
4}
source

RoyaltyInfo represents royalty information for a token.

type TokenID

ident
1type TokenID string
source

Methods on TokenID

func String

method on TokenID
1func (t TokenID) String() string
source

type TokenURI

ident
1type TokenURI string
source

Methods on TokenURI

func String

method on TokenURI
1func (t TokenURI) String() string
source

type Trait

struct
1type Trait struct {
2	DisplayType string
3	TraitType   string
4	Value       string
5}
source

Imports 6

Source Files 12