Skip to content

Commit

Permalink
0.1.0 ready > Merge pull request #21 from Itheum/d-david
Browse files Browse the repository at this point in the history
Removed ENVs and changed mint logic
  • Loading branch information
newbreedofgeek authored Aug 16, 2023
2 parents 7c5a584 + 21151cb commit b8365d2
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 169 deletions.
93 changes: 75 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This SDK is currently focused on interacting with the Itheum's Data NFT technolo

## Usage in 3rd party dApps

- install this SDK via `npm i @itheum/sdk-mx-data-nft`
- Install this SDK via `npm i @itheum/sdk-mx-data-nft`
- Methods supported are given below is `SDK Docs`

## SDK DOCS
Expand Down Expand Up @@ -50,21 +50,20 @@ response.forEach(async (nft) => {
dataNfts.push(data);
});

// Retrives the DataNfts owned by a address
// Retrieves the DataNfts owned by a address
const address = 'address';
const dataNfts = [];
dataNfts = await DataNft.ownedByAddress(address);

// Retrives the DataNft message from marshal to sign

// Retrieves the DataNft message from marshal to sign
const dataNft = DataNft.createFromApi(nonce);
const message = await dataNft.messageToSign();

// Sign the message with a wallet
const signature = 'signature';

// Unlock the data inside the dataNft
dataNft.viewData(message, signature);
dataNft.viewData(message, signature); // optional params "stream" (stream out data instead of downloading file), "fwdAllHeaders"/"fwdHeaderKeys" can be used to pass headers like Authorization to origin servers
```

### 2. Interacting with Data NFT Minter
Expand All @@ -74,27 +73,62 @@ import { DataNftMinter } from '@itheum/sdk-mx-data-nft';

const dataNftMinter = new DataNftMinter('devnet' | 'testnet' | 'mainnet');

// View minter smart contract rewquirements
// View minter smart contract requirements
const requirements = await dataNftMinter.viewMinterRequirements('address');

// View contract pause state
const result = await dataNftMarket.viewContractPauseState();
```

#### Create a mint transaction

// Create a mint transaction
Method 1: Mint a new Data NFT with Ithuem generated image and traits.
Currently only supports [nft.storage](https://nft.storage/docs/quickstart/#get-an-api-token).

```typescript
const transaction = await dataNftMarket.mint(
new Address('erd1'),
'TEST-TOKEN',
'https://marshal.com',
'https://streamdata.com',
'https://previewdata',
15,
1000,
'Test Title',
'Test Description',
10
new Address('erd1'),
'TEST-TOKEN',
'https://marshal.com',
'https://streamdata.com',
'https://previewdata',
15,
1000,
'Test Title',
'Test Description',
10000000000,
options: {
nftStorageToken:"API TOKEN",
}
);
```

Method 2: Mint a new Data NFT with custom image and traits.
Traits should be compliant with the Itheum [traits structure](#traits-structure).

```typescript
const transaction = await dataNftMarket.mint(
new Address('erd1'),
'TEST-TOKEN',
'https://marshal.com',
'https://streamdata.com',
'https://previewdata',
15,
1000,
'Test Title',
'Test Description',
10000000000,
options: {
imageUrl:"https://imageurl.com",
traitsUrl:"https://traitsurl.com",
}

);
```

// Create a burn transaction
#### Create a burn transaction

```typescript
const transaction = await dataNftMarket.burn(
new Address('erd1'),
dataNftNonce,
Expand Down Expand Up @@ -161,3 +195,26 @@ const result = dataNftMarket.withdrawCancelledOffer(new Address(''), 0);
// Create changeOfferPrice transaction
const result = dataNftMarket.changeOfferPrice(new Address(''), 0, 0);
```

### Traits structure

```json
{
"description": "Data NFT description", //required
"attributes": [
{
"trait_type": "Creator", //required
"value": "creator address"
},
{
"trait_type": "Data Preview URL", //required
"value": "https://previewdata.com"
},
{
"trait_type": "extra trait",
"value": "extra trait value"
},
...
]
}
```
13 changes: 2 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itheum/sdk-mx-data-nft",
"version": "0.0.8",
"version": "0.1.0",
"description": "SDK for Itheum's Data NFT Technology on MultiversX Blockchain",
"main": "out/index.js",
"types": "out/index.d.js",
Expand All @@ -19,7 +19,6 @@
"@multiversx/sdk-core": "12.6.0",
"@multiversx/sdk-network-providers": "1.5.0",
"bignumber.js": "^9.1.1",
"dotenv": "^16.0.3",
"nft.storage": "^7.0.3"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ export const networkConfiguration: { [key in EnvironmentsEnum]: Config } = {
mainnet: mainnetNetworkConfig,
testnet: testnetNetworkConfig
};

export const imageService: { [key in EnvironmentsEnum]: string } = {
devnet: 'https://api.itheumcloud-stg.com/datadexapi',
mainnet: 'https://api.itheumcloud.com/datadexapi',
testnet: ''
};
40 changes: 17 additions & 23 deletions src/datanft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,25 @@ export class DataNft {
}

/**
* Creates a DataNft from a API response containing the NFT details.
* Creates a DataNft or an array of DataNft from either a single NFT details API response or an array of NFT details API response.
*
* Useful for creating an array of DataNft.
* @param payload NFT details API response
* @param payload NFT details API response, can be a single item or an array of items
*/
static createFromApiResponse(payload: NftType): DataNft {
const dataNft = parseDataNft(payload);

return dataNft;
}

/**
* Creates an array of DataNft from an array of NFT details API response.
*
* @param payload NFT details API response
*/
static createFromApiResponseBulk(payload: NftType[]): DataNft[] {
static createFromApiResponseOrBulk(payload: NftType | NftType[]): DataNft[] {
const dataNfts: DataNft[] = [];
payload.forEach((nft: NftType) => {
dataNfts.push(this.createFromApiResponse(nft));
});

return dataNfts;
const parseNft = (nft: NftType) => {
const dataNft = parseDataNft(nft);
dataNfts.push(dataNft);
};

if (Array.isArray(payload)) {
payload.forEach(parseNft);
return dataNfts;
} else {
parseNft(payload as NftType);
return dataNfts;
}
}

/**
Expand Down Expand Up @@ -175,10 +171,8 @@ export class DataNft {
`${this.apiConfiguration}/accounts/${address}/nfts?size=10000&collections=${identifier}&withSupply=true`
);
const data = await res.json();
const dataNfts: DataNft[] = [];
data.forEach((nft: NftType) => {
dataNfts.push(this.createFromApiResponse(nft));
});
const dataNfts: DataNft[] = this.createFromApiResponseOrBulk(data);

return dataNfts;
}

Expand Down
2 changes: 1 addition & 1 deletion src/marketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class DataNftMarket {
readonly env: string;

/**
* Creates a new instance of the DataNftMarket which can be used to interact with the DataNFT-FTs inside the marketplace
* Creates a new instance of the DataNftMarket which can be used to interact with the marketplace smart contract
* @param env 'devnet' | 'mainnet' | 'testnet'
* @param timeout Timeout for the network provider (DEFAULT = 10000ms)
*/
Expand Down
Loading

0 comments on commit b8365d2

Please sign in to comment.