Nfts
@nevermined-io/nevermined-sdk-js / Nfts
Class: Nfts
Nevermined Nft module
Hierarchy
Instantiable
↳
Nfts
Table of contents
Constructors
Accessors
Methods
- access
- addresses
- balance
- burn
- buySecondaryMarketNft
- checkExists
- create
- create721
- createWithRoyalties
- details
- downloadFiles
- findSigner
- getNftContractAddress
- listOnSecondaryMarkets
- mint
- order
- order721
- ownerOf
- release721Rewards
- releaseRewards
- releaseSecondaryMarketRewards
- setApprovalForAll
- setInstanceConfig
- transfer
- transfer721
- transferForDelegate
- addressesStatic
- findSignerStatic
- getInstance
- setInstanceConfig
Constructors
constructor
• new Nfts()
Inherited from
Instantiable.constructor
Accessors
artifactsFolder
• Protected
get
artifactsFolder(): string
Returns
string
Inherited from
Instantiable.artifactsFolder
Defined in
src/Instantiable.abstract.ts:96
config
• Protected
get
config(): Config
Returns
Inherited from
Instantiable.config
Defined in
src/Instantiable.abstract.ts:80
instanceConfig
• Protected
get
instanceConfig(): InstantiableConfig
Returns
InstantiableConfig
Inherited from
Instantiable.instanceConfig
Defined in
src/Instantiable.abstract.ts:100
instantiableConfig
• Protected
get
instantiableConfig(): InstantiableConfig
Returns
InstantiableConfig
Inherited from
Instantiable.instantiableConfig
Defined in
src/Instantiable.abstract.ts:73
logger
• Protected
get
logger(): Logger
Returns
Inherited from
Instantiable.logger
Defined in
src/Instantiable.abstract.ts:87
nevermined
• Protected
get
nevermined(): Nevermined
Returns
Inherited from
Instantiable.nevermined
Defined in
src/Instantiable.abstract.ts:33
web3
• Protected
get
web3(): JsonRpcProvider
Returns
JsonRpcProvider
Inherited from
Instantiable.web3
Defined in
src/Instantiable.abstract.ts:63
Methods
access
▸ access(did
, consumer
, destination?
, index?
, agreementId?
): Promise
<boolean
>
Access the files associated with an NFT.
Remarks
This function will call the Node that will check if all the access conditions where fulfilled before providing the files.
Example
// TODO
Parameters
Name | Type | Default value | Description |
---|---|---|---|
did | string | undefined | The Decentralized Identifier of the NFT asset. |
consumer | Account | undefined | The NFT holder account. |
destination? | string | undefined | The download destination for the files. |
index? | number | undefined | - |
agreementId | string | '0x' | - |
Returns
Promise
<boolean
>
true if the access was successful.
Defined in
addresses
▸ addresses(): Promise
<string
[]>
Returns
Promise
<string
[]>
Inherited from
Instantiable.addresses
Defined in
src/Instantiable.abstract.ts:129
balance
▸ balance(did
, account
): Promise
<default
>
Get the NFT balance for a particular did
Example
// TODO
Parameters
Name | Type | Description |
---|---|---|
did | string | The Decentralized Identifier of the NFT asset. |
account | Account | The account to check the balance of. |
Returns
Promise
<default
>
The amount of NFTs owned by the account.
Defined in
burn
▸ burn(did
, nftAmount
, publisher
, params?
): Promise
<ContractReceipt
>
Burn NFTs associated with an asset.
Remarks
The publisher can only burn NFTs that it owns. NFTs that were already transferred cannot be burned by the publisher.
Example
// TODO
Parameters
Name | Type | Description |
---|---|---|
did | string | The Decentralized Identifier of the NFT asset. |
nftAmount | default | The amount of NFTs to burn. |
publisher | Account | The account of the publisher of the NFT. |
params? | TxParameters | Optional transaction parameters. |
Returns
Promise
<ContractReceipt
>
The ethers.ContractReceipt
Defined in
buySecondaryMarketNft
▸ buySecondaryMarketNft(consumer
, nftAmount?
, agreementIdSeed
, params?
): Promise
<boolean
>
Buys a number of listed NFTs on secondary markets.
Example
// TODO
Throws
NFTError Thrown if there is an error buying the NFT.
Parameters
Name | Type | Description |
---|---|---|
consumer | Account | The account of the buyer/consumer. |
nftAmount | default | The number of assets to buy. 1 by default. |
agreementIdSeed | string | - |
params? | TxParameters | - |
Returns
Promise
<boolean
>
true if the buy was successful.
Defined in
checkExists
▸ Protected
checkExists(address
): Promise
<boolean
>
Returns true of contract exists else it throws.
Parameters
Name | Type |
---|---|
address | string |
Returns
Promise
<boolean
>
true if the contract exists.
Inherited from
Instantiable.checkExists
Defined in
src/Instantiable.abstract.ts:44
create
▸ create(metadata
, publisher
, cap
, royaltyAttributes
, assetRewards
, nftAmount?
, erc20TokenAddress?
, preMint?
, nftMetadata?
, appId?
, txParams?
): SubscribablePromise
<CreateProgressStep
, DDO
>
Create a new NFT Nevermined NFT.
Example
// TODO
Parameters
Name | Type | Description |
---|---|---|
metadata | MetaData | The metadata associated with the NFT. |
publisher | Account | The account of the creator od the NFT. |
cap | default | The max number of nfts. |
royaltyAttributes | RoyaltyAttributes | The royalties associated with the NFT. |
assetRewards | default | The sales reward distribution. |
nftAmount | default | The amount of NFTs that an address needs to hold in order to access the DID's protected assets. Leave it undefined and it will default to 1. |
erc20TokenAddress? | string | The ERC-20 Token used to price the NFT. |
preMint? | boolean | Set to true to mint nftAmount during creation. |
nftMetadata? | string | Url to the NFT metadata. |
appId? | string | The id of the application creating the NFT. |
txParams? | TxParameters | Optional transaction parameters |
Returns
SubscribablePromise
<CreateProgressStep
, DDO
>
The newly registered DDO.
Defined in
create721
▸ create721(metadata
, publisher
, assetRewards
, nftTokenAddress
, erc20TokenAddress?
, royaltyAttributes?
, nftMetadata?
, nftTransfer?
, duration?
, appId?
, txParams?
): SubscribablePromise
<CreateProgressStep
, DDO
>
Create a new Nevermined NFT-721.
Example
// TODO
Parameters
Name | Type | Default value | Description |
---|---|---|---|
metadata | MetaData | undefined | The metadata associated with the NFT. |
publisher | Account | undefined | The account of the creator od the NFT. |
assetRewards | default | undefined | The sales reward distribution. |
nftTokenAddress | string | undefined | The address of the ERC-721 contract |
erc20TokenAddress? | string | undefined | The ERC-20 Token used to price the NFT. |
royaltyAttributes? | RoyaltyAttributes | undefined | The royalties associated with the NFT. |
nftMetadata? | string | undefined | Url to the NFT metadata. |
nftTransfer | boolean | true | TODO |
duration | number | 0 | TODO |
appId? | string | undefined | Id of the application creating this NFT. |
txParams? | TxParameters | undefined | Optional transaction parameters |
Returns
SubscribablePromise
<CreateProgressStep
, DDO
>
The newly registered DDO.
Defined in
createWithRoyalties
▸ createWithRoyalties(metadata
, publisher
, cap
, royaltyAttributes
, assetRewards
, nftAmount?
, erc20TokenAddress?
, preMint?
, nftMetadata?
, nftType?
, appId?
, txParams?
): SubscribablePromise
<CreateProgressStep
, DDO
>
Create a new Nevermined NFT with royalties.
Example
// TODO
Parameters
Name | Type | Default value | Description |
---|---|---|---|
metadata | MetaData | undefined | The metadata associated with the NFT. |
publisher | Account | undefined | The account of the creator od the NFT. |
cap | default | undefined | The max number of nfts. |
royaltyAttributes | RoyaltyAttributes | undefined | The royalties associated with the NFT. |
assetRewards | default | undefined | The sales reward distribution. |
nftAmount | default | undefined | The amount of NFTs that an address needs to hold in order to access the DID's protected assets. Leave it undefined and it will default to 1. |
erc20TokenAddress? | string | undefined | The ERC-20 Token used to price the NFT. |
preMint? | boolean | undefined | Set to true to mint nftAmount during creation. |
nftMetadata? | string | undefined | Url to the NFT metadata. |
nftType | NeverminedNFTType | NeverminedNFT1155Type.nft1155 | - |
appId? | string | undefined | The id of the application creating the NFT. |
txParams? | TxParameters | undefined | Optional transaction parameters |
Returns
SubscribablePromise
<CreateProgressStep
, DDO
>
The newly registered DDO.
Defined in
details
▸ details(did
): Promise
<{ blockNumberUpdated
: number
; lastChecksum
: any
; lastUpdatedBy
: any
; mintCap
: number
; nftSupply
: number
; owner
: any
; providers
: any
; royalties
: number
; royaltyScheme
: RoyaltyKind
; url
: any
}>
Get the details of an NFT
Example
// TODO
Parameters
Name | Type | Description |
---|---|---|
did | string | The Decentralized Identifier of the NFT asset. |
Returns
Promise
<{ blockNumberUpdated
: number
; lastChecksum
: any
; lastUpdatedBy
: any
; mintCap
: number
; nftSupply
: number
; owner
: any
; providers
: any
; royalties
: number
; royaltyScheme
: RoyaltyKind
; url
: any
}>
The details of the NFT.
Defined in
downloadFiles
▸ Private
downloadFiles(agreementId
, ddo
, consumer
, destination?
, index?
): Promise
<boolean
>
Parameters
Name | Type |
---|---|
agreementId | string |
ddo | DDO |
consumer | Account |
destination? | string |
index? | number |
Returns
Promise
<boolean
>
Defined in
findSigner
▸ findSigner(from
): Promise
<Signer
>
Parameters
Name | Type |
---|---|
from | string |
Returns
Promise
<Signer
>
Inherited from
Instantiable.findSigner
Defined in
src/Instantiable.abstract.ts:105
getNftContractAddress
▸ getNftContractAddress(ddo
): string
| number
| string
[]
Get the NFT contract address associated with a Nevermined asset.
Example
// TODO
Parameters
Name | Type | Description |
---|---|---|
ddo | DDO | The DDO of the asset. |
Returns
string
| number
| string
[]
The NFT contract address.
Defined in
listOnSecondaryMarkets
▸ listOnSecondaryMarkets(ddo
, assetRewards
, nftAmount
, provider
, token
, owner
): Promise
<string
>
After purchase re-list an NFT to enable secondary market sales.
Example
// TODO
Throws
NFTError Thrown if there is an error listing the NFT.
Parameters
Name | Type | Description |
---|---|---|
ddo | DDO | The DDO of the asset. |
assetRewards | default | The current setup of asset rewards. |
nftAmount | default | The number of NFTs put up for secondary sale. |
provider | string | The address that will be the provider of the secondary sale. |
token | default | - |
owner | string | The account of the current owner. |
Returns
Promise
<string
>
the agreementId of the secondary sale.
Defined in
mint
▸ mint(did
, nftAmount
, publisher
, params?
): Promise
<ContractReceipt
>
Mint NFTs associated with an asset.
Remarks
This function can be called multiple times as long as the minting does not exceed the maximum cap set during creation.
Example
// TODO
Parameters
Name | Type | Description |
---|---|---|
did | string | The Decentralized Identifier of the NFT asset. |
nftAmount | default | The amount of NFTs to mint. |
publisher | Account | The account of the publisher of the NFT. |
params? | TxParameters | Optional transaction parameters. |
Returns
Promise
<ContractReceipt
>
The ethers.ContractReceipt
Defined in
order
▸ order(did
, nftAmount
, consumer
, txParams?
): SubscribablePromise
<OrderProgressStep
, string
>
Buy NFTs.
Remarks
This will lock the funds of the consumer in escrow pending the transfer of the NFTs from the publisher.
Example
// TODO
Parameters
Name | Type | Description |
---|---|---|
did | string | The Decentralized Identifier of the NFT asset. |
nftAmount | default | The amount of NFTs to buy. |
consumer | Account | The account of the NFT buyer. |
txParams? | TxParameters | Optional transaction parameters. |
Returns
SubscribablePromise
<OrderProgressStep
, string
>
The agreement ID.
Defined in
order721
▸ order721(did
, consumer
, txParams?
): SubscribablePromise
<OrderProgressStep
, string
>
Buy NFT-721.
Remarks
This will lock the funds of the consumer in escrow pending the transfer of the NFTs from the publisher.
Example
// TODO
Parameters
Name | Type | Description |
---|---|---|
did | string | The Decentralized Identifier of the NFT asset. |
consumer | Account | The account of the NFT buyer. |
txParams? | TxParameters | Optional transaction parameters. |
Returns
SubscribablePromise
<OrderProgressStep
, string
>
The agreement ID.
Defined in
ownerOf
▸ ownerOf(did
, nftTokenAddress
, agreementId?
): Promise
<string
>
Get the owner of the NFT
Example
// TODO
Parameters
Name | Type | Description |
---|---|---|
did | string | The Decentralized identifier of the NFT asset. |
nftTokenAddress | string | The address of the ERC-721 contract. |
agreementId? | string | The NFT sales agreement id. |
Returns
Promise
<string
>
The address of the NFT owner.
Defined in
release721Rewards
▸ release721Rewards(agreementId
, did
, publisher
, txParams?
): Promise
<boolean
>
Release the funds from escrow.
Remarks
A publisher is able to release the funds put on escrow by the consumer after transferring the NFTs.
Example
// TODO
Throws
NFTError Thrown if there is an error releasing the rewards.
Parameters
Name | Type | Description |
---|---|---|
agreementId | string | The NFT sales agreement id. |
did | string | The Decentralized identifier of the NFT asset. |
publisher | Account | The current owner of the NFTs. |
txParams? | TxParameters | Optional transaction parameters. |
Returns
Promise
<boolean
>
true if the funds release was successful.
Defined in
releaseRewards
▸ releaseRewards(agreementId
, did
, nftAmount
, publisher
, txParams?
): Promise
<boolean
>
Release the funds from escrow.
Remarks
A publisher is able to release the funds put on escrow by the consumer after transferring the NFTs.
Example
// TODO
Throws
NFTError Thrown if there is an error releasing the rewards
Parameters
Name | Type | Description |
---|---|---|
agreementId | string | The NFT sales agreement id. |
did | string | The Decentralized identifier of the NFT asset. |
nftAmount | default | The amount of NFTs to transfer. |
publisher | Account | The current owner of the NFTs. |
txParams? | TxParameters | Optional transaction parameters. |
Returns
Promise
<boolean
>
true if the funds release was successful.
Defined in
releaseSecondaryMarketRewards
▸ releaseSecondaryMarketRewards(owner
, consumer
, agreementIdSeed
, params?
): Promise
<boolean
>
Used to release the secondary market NFT & the locked rewards.
Example
// TODO
Throws
NFTError Thrown if there is an error releasing the rewards.
Parameters
Name | Type | Description |
---|---|---|
owner | Account | The owner account. |
consumer | Account | - |
agreementIdSeed | string | - |
params? | TxParameters | - |
Returns
Promise
<boolean
>
true if the transaction was successful.
Defined in
setApprovalForAll
▸ setApprovalForAll(operatorAddress
, approved
, from
): Promise
<ContractReceipt
>
Enable or disable NFT transfer rights for an operator.
See
Example
// TODO
Parameters
Name | Type | Description |
---|---|---|
operatorAddress | string | The address that of the operator we want to give transfer rights to. |
approved | boolean | Give or remove transfer rights from the operator. |
from | Account | The account that wants to give transfer rights to the operator. |
Returns
Promise
<ContractReceipt
>
The ethers.ContractReceipt
Defined in
setInstanceConfig
▸ Protected
setInstanceConfig(config
): void
Parameters
Name | Type |
---|---|
config | InstantiableConfig |
Returns
void
Inherited from
Instantiable.setInstanceConfig
Defined in
src/Instantiable.abstract.ts:171
transfer
▸ transfer(agreementId
, did
, nftAmount
, publisher
, txParams?
): Promise
<boolean
>
Transfer NFTs to the consumer.
Remarks
A publisher/provider will check if the consumer put the funds in escrow and execute the transfer in order to be able to release the rewards.
Example
// TODO
Throws
NFTError Thrown if there is an error transferring the NFT
Parameters
Name | Type | Description |
---|---|---|
agreementId | string | The NFT sales agreement id. |
did | string | The Decentralized identifier of the NFT asset. |
nftAmount | default | The number of NFTs to transfer. |
publisher | Account | The current owner of the NFTs. |
txParams? | TxParameters | Optional transaction parameters. |
Returns
Promise
<boolean
>
true if the transfer was successful.
Defined in
transfer721
▸ transfer721(agreementId
, did
, publisher
, txParams?
): Promise
<boolean
>
Transfer NFT-721 to the consumer.
Remarks
A publisher/provider will check if the consumer put the funds in escrow and execute the transfer in order to be able to release the rewards.
Example
// TODO
Throws
NFTError Thrown if there is an error transferring the NFT
Parameters
Name | Type | Description |
---|---|---|
agreementId | string | The NFT sales agreement id. |
did | string | The Decentralized identifier of the NFT asset. |
publisher | Account | The current owner of the NFTs. |
txParams? | TxParameters | Optional transaction parameters. |
Returns
Promise
<boolean
>
true if the transfer was successful.
Defined in
transferForDelegate
▸ transferForDelegate(agreementId
, nftHolder
, nftReceiver
, nftAmount
, ercType?
): Promise
<boolean
>
Asks the Node to transfer the NFT on behalf of the publisher.
Remarks
This is useful when the consumer does not want to wait for the publisher to transfer the NFT once the payment is made. Assuming the publisher delegated transfer permissions to the Node.
One example would be a marketplace where the user wants to get access to the NFT as soon as the payment is made
Example
// TODO
Parameters
Name | Type | Default value | Description |
---|---|---|---|
agreementId | string | undefined | The NFT sales agreement id. |
nftHolder | string | undefined | The address of the current owner of the NFT. |
nftReceiver | string | undefined | The address where the NFT should be transferred. |
nftAmount | default | undefined | The amount of NFTs to transfer. |
ercType | ERCType | 1155 | The Type of the NFT ERC (1155 or 721). |
Returns
Promise
<boolean
>
true if the transfer was successful.
Defined in
addressesStatic
▸ Static
addressesStatic(config
, web3
): Promise
<string
[]>
Parameters
Name | Type |
---|---|
config | Config |
web3 | JsonRpcProvider |
Returns
Promise
<string
[]>
Inherited from
Instantiable.addressesStatic
Defined in
src/Instantiable.abstract.ts:142
findSignerStatic
▸ Static
findSignerStatic(config
, web3
, from
): Promise
<Signer
>
Parameters
Name | Type |
---|---|
config | Config |
web3 | JsonRpcProvider |
from | string |
Returns
Promise
<Signer
>
Inherited from
Instantiable.findSignerStatic
Defined in
src/Instantiable.abstract.ts:115
getInstance
▸ Static
getInstance(config
): Promise
<Nfts
>
Parameters
Name | Type |
---|---|
config | InstantiableConfig |
Returns
Promise
<Nfts
>
Overrides
Instantiable.getInstance
Defined in
setInstanceConfig
▸ Static
Protected
setInstanceConfig<T
>(instance
, instantiableConfig
): void
Type parameters
Name | Type |
---|---|
T | extends Instantiable <T > |
Parameters
Name | Type |
---|---|
instance | T |
instantiableConfig | InstantiableConfig |
Returns
void
Inherited from
Instantiable.setInstanceConfig