From 0e9817c2a257b2cd08866fbb29922dad83992773 Mon Sep 17 00:00:00 2001 From: Claudiu Ion Lataretu Date: Thu, 3 Jun 2021 15:48:15 +0300 Subject: [PATCH 1/4] Add method to get NFT Token Metadata from apiProvider Signed-off-by: Claudiu Ion Lataretu --- src/apiProvider.ts | 5 ++++ src/nftToken.ts | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/nftToken.ts diff --git a/src/apiProvider.ts b/src/apiProvider.ts index c10360f4..a98a297c 100644 --- a/src/apiProvider.ts +++ b/src/apiProvider.ts @@ -7,6 +7,7 @@ import { Stats } from "./stats"; import { TransactionHash } from "./transaction"; import { TransactionOnNetwork } from "./transactionOnNetwork"; import { ESDTToken } from "./esdtToken"; +import { NFTToken } from "./nftToken"; const JSONbig = require("json-bigint"); /** @@ -53,6 +54,10 @@ export class ApiProvider implements IApiProvider { return this.doGetGeneric(`tokens/${tokenIdentifier}`, (response) => ESDTToken.fromHttpResponse(response)); } + async getNFTToken(tokenIdentifier: string): Promise { + return this.doGetGeneric(`nfts/${tokenIdentifier}`, (response) => NFTToken.fromHttpResponse(response)); + } + /** * Get method that receives the resource url and on callback the method used to map the response. */ diff --git a/src/nftToken.ts b/src/nftToken.ts new file mode 100644 index 00000000..69f0c0c1 --- /dev/null +++ b/src/nftToken.ts @@ -0,0 +1,63 @@ + +export class NFTToken { + token: string = ''; + name: string = ''; + type: string = ''; + owner: string = ''; + minted: string = ''; + burnt: string = ''; + decimals: number = 0; + isPaused: boolean = false; + canUpgrade: boolean = false; + canMint: boolean = false; + canBurn: boolean = false; + canChangeOwner: boolean = false; + canPause: boolean = false; + canFreeze: boolean = false; + canWipe: boolean = false; + canAddSpecialRoles: boolean = false; + canTransferNFTCreateRole: boolean = false; + NFTCreateStopped: boolean = false; + wiped: string = '0'; + + constructor(init?: Partial) { + Object.assign(this, init); + } + + static fromHttpResponse(response: { + token: string, + name: string, + type: string, + owner: string, + minted: string, + burnt: string, + decimals: number, + isPaused: boolean, + canUpgrade: boolean, + canMint: boolean, + canBurn: boolean, + canChangeOwner: boolean, + canPause: boolean, + canFreeze: boolean, + canWipe: boolean, + canAddSpecialRoles: boolean, + canTransferNFTCreateRole: boolean, + NFTCreateStopped: boolean, + wiped: string + }) { + let nftToken = new NFTToken(response); + return nftToken + } + + getTokenName() { + return this.name; + } + + getTokenIdentifier() { + return this.token; + } + + getTokenType() { + return this.type; + } +} From b723957958d6b1fc2f7ee9de4cb3ad8a6b485666 Mon Sep 17 00:00:00 2001 From: Claudiu Ion Lataretu Date: Mon, 7 Jun 2021 11:55:02 +0300 Subject: [PATCH 2/4] add missing filed for esdtToken Signed-off-by: Claudiu Ion Lataretu --- src/esdtToken.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/esdtToken.ts b/src/esdtToken.ts index c3baf6e6..8b556bb2 100644 --- a/src/esdtToken.ts +++ b/src/esdtToken.ts @@ -2,6 +2,7 @@ export class ESDTToken { token: string = ''; name: string = ''; + type: string = ''; owner: string = ''; minted: string = ''; burnt: string = ''; @@ -22,6 +23,7 @@ export class ESDTToken { static fromHttpResponse(response: { token: string, name: string, + type: string, owner: string, minted: string, burnt: string, @@ -47,4 +49,4 @@ export class ESDTToken { return this.token; } -} \ No newline at end of file +} From 91df25ba3c3366127fc7aab73ee502c03e24f017 Mon Sep 17 00:00:00 2001 From: Claudiu Ion Lataretu Date: Mon, 7 Jun 2021 11:55:31 +0300 Subject: [PATCH 3/4] change return type for getNFTToken method Signed-off-by: Claudiu Ion Lataretu --- src/apiProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apiProvider.ts b/src/apiProvider.ts index a98a297c..a18a040c 100644 --- a/src/apiProvider.ts +++ b/src/apiProvider.ts @@ -54,7 +54,7 @@ export class ApiProvider implements IApiProvider { return this.doGetGeneric(`tokens/${tokenIdentifier}`, (response) => ESDTToken.fromHttpResponse(response)); } - async getNFTToken(tokenIdentifier: string): Promise { + async getNFTToken(tokenIdentifier: string): Promise { return this.doGetGeneric(`nfts/${tokenIdentifier}`, (response) => NFTToken.fromHttpResponse(response)); } From 07f4139baa781c252b7fff1db34c75da6e5b3f9b Mon Sep 17 00:00:00 2001 From: Claudiu Ion Lataretu Date: Mon, 7 Jun 2021 14:47:28 +0300 Subject: [PATCH 4/4] patch update erdjs to 5.0.1 Signed-off-by: Claudiu Ion Lataretu --- CHANGELOG.md | 4 ++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3e5ed94..74d4e77d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes will be documented in this file. Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. +## [5.0.1] - 07.06.2021 + +- [Feat/nft token #3](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/3) + ## [5.0.0] - 19.05.2021 - [Remove event target and add callback #310](https://github.com/ElrondNetwork/elrond-sdk/pull/310) diff --git a/package-lock.json b/package-lock.json index 0c53dd0c..bde09766 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@elrondnetwork/erdjs", - "version": "5.0.0", + "version": "5.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index be82b017..daff44d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@elrondnetwork/erdjs", - "version": "5.0.0", + "version": "5.0.1", "description": "Smart Contracts interaction framework", "main": "out/index.js", "types": "out/index.d.js",