Utility
The utility module provides many convenience tools for interacting with the ZDK
The utility functions can be roughly split into 3 categories:
Type Constructors
Hash Utilities
EIP-712 Utilities
Type Constructors
The Zora protocol utilizes a number of structs to encode data as parameters. The ZDK provides some type constructors that can perform some basic validation and return a properly formatted struct.
constructMediaData
Accepts the arguments for constructing
MediaData
type.Validates that the URIs begins with
https://
.Validates that the hashes are exactly 32 bytes in length.
Name
Type
Description
tokenURI
string
The uri where the media's content can be accessed
metadataURI
string
The uri where the media's metadata can be accessed
contentHash
BytesLike
The sha256 hash of the media's content
metadataHash
BytesLike
The sha256 hash of the media's metadata
constructAsk
Parses and Validates the currency address to ensure its a valid Ethereum Address
Name
Type
Description
currency
string
The currency address of the Ask
amount
BigNumberish
The amount of the Ask in the currency's atomic units
constructBid
Parses and Validates the bidder, recipient, and currency addresses.
Rounds the SellOnShare to 4 decimals of precision
Name
Type
Description
currency
string
The currency address of the Bid
amount
BigNumberish
The amount of the Bid in the currency's atomic units
bidder
string
The address of the Bid's bidder
recipient
string
The address of the Bid's recipient
sellOnShare
number
The sellOnShare of the Bid
constructBidShares
Accepts
number
args, converts them to ethersBigNumber
type with 18 decimals of precision.Performs validation that the
BigNumber
representations sum to100
inBigNumber
form.
Name
Type
Description
creator
number
The creator bidshare for the media
owner
number
The owner bidshare for the media
prevOwner
number
The prevOwner bidshare for the media
Hashing Utilities
All pieces of media minted on the Zora Protocol must etch a sha256
hash of both its content and metadata onto the blockchain. As such it is important developers interacting with Zora have reliable ways to create and verify hashes of data of all types and sizes.
The majority of NFT protocols don't currently support storing integrity tools like a sha256
checksum. This means that if the URL that other NFTs were to ever change, the NFT would become corrupted with no way to verify the originality of the media.
By providing an on-chain integrity check, anyone is able to ensure that a Zora NFT has not been corrupted in any way.
sha256FromBuffer
Create a sha256 from a Buffer
object
Name
Type
Description
buffer
Buffer
The Buffer to be hashed
sha256FromHexString
Create a sha256 hash from a hex string. Hex string must be prefixed with 0x
Name
Type
Description
data
string
The hex encoded data to be hashed
sha256FromFile
Create a sha256 hash from a local file This is most useful for the hashing of large files. It uses a readStream to load bits into memory via a buffer and construct a hash as it consumes the contents of the file.
Name
Type
Description
pathToFile
string
The path to the file to be hashed
chunkSize
number
The chunk size in bytes for the read stream to read into memory
EIP-712 Utilities
signPermitMessage
Permit was specified as an extension of ERC-20 standard to allow for users to issue approval
to accounts without needing ETH
.
We have extended it further to be used for the Zora Protocol, so that users can delegate approvals to other smart contracts to perform actions that approved
users can do such as:
setAsk
acceptBid
updateContentURI
updateMetadataURI
transfer
For now, the signer must be an ethers
Wallet
object. But soon we will support any Signer
.
Name
Type
Description
owner
Wallet
The owners's wallet
toAddress
string
The address being granted the permit
mediaId
number
The ID of the media
nonce
number
The permitNonce of the owner address
deadline
number
The deadline of the signature to be included in a tx
domain
EIP712Domain
The EIP712Domain for the permit sig
signMintWithSigMessage
We extended EIP-712
to allow for creators to mint
without needing ETH
. A user can sign a mintWithSig
message and use a trusted relayer to relay the transaction and mint on their behalf.
Name
Type
Description
owner
Wallet
The owners's wallet
contentHash
BytesLike
The sha256 hash of the media's content
metadataHash
BytesLike
The sha256 hash of the media's metadata
creatorShareBN
BigNumber
The creator share of the media
nonce
number
The mintWithSigNonce of the owner address
deadline
number
The deadline of the signature to be included in a tx
domain
EIP712Domain
The EIP712Domain for the mintWithSig signature
recoverSignatureFromPermit
Recover the address of the signing private key of a Permit
message
Name
Type
Description
owner
Wallet
The owners's wallet
toAddress
string
The address being granted the permit
mediaId
number
The ID of the media
nonce
number
The permitNonce of the owner address
deadline
number
The deadline of the signature to be included in a tx
domain
EIP712Domain
The EIP712Domain for the permit sig
sig
EIP712Signature
The EIP712Signature to have an address recovered
recoverSignatureFromMintWithSig
Recover the address of the signing private key of a mintWithSig
message
Name
Type
Description
owner
Wallet
The owners's wallet
contentHash
BytesLike
The sha256 hash of the media's content
metadataHash
BytesLike
The sha256 hash of the media's metadata
creatorShareBN
BigNumber
The creator share of the media
nonce
number
The mintWithSigNonce of the owner address
deadline
number
The deadline of the signature to be included in a tx
domain
EIP712Domain
The EIP712Domain for the mintWithSig signature
sig
EIP712Signature
The EIP712Signature to have an address recovered
Last updated