mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
add estimateGas parameter to NFT
This commit is contained in:
parent
863ba49154
commit
c92aaeba47
@ -26,7 +26,7 @@ export class Nft extends SmartContract {
|
|||||||
* @param {Number} templateIndex NFT template index
|
* @param {Number} templateIndex NFT template index
|
||||||
* @return {Promise<string>} ERC20 Datatoken address
|
* @return {Promise<string>} ERC20 Datatoken address
|
||||||
*/
|
*/
|
||||||
public async createDatatoken(
|
public async createDatatoken<G extends boolean = false>(
|
||||||
nftAddress: string,
|
nftAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
minter: string,
|
minter: string,
|
||||||
@ -37,8 +37,9 @@ export class Nft extends SmartContract {
|
|||||||
cap: string,
|
cap: string,
|
||||||
name?: string,
|
name?: string,
|
||||||
symbol?: string,
|
symbol?: string,
|
||||||
templateIndex?: number
|
templateIndex?: number,
|
||||||
): Promise<string> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? string : number> {
|
||||||
if ((await this.getNftPermissions(nftAddress, address)).deployERC20 !== true) {
|
if ((await this.getNftPermissions(nftAddress, address)).deployERC20 !== true) {
|
||||||
throw new Error(`Caller is not DatatokenDeployer`)
|
throw new Error(`Caller is not DatatokenDeployer`)
|
||||||
}
|
}
|
||||||
@ -61,6 +62,7 @@ export class Nft extends SmartContract {
|
|||||||
[this.web3.utils.toWei(cap), this.web3.utils.toWei(feeAmount)],
|
[this.web3.utils.toWei(cap), this.web3.utils.toWei(feeAmount)],
|
||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call createERC20 token function of the contract
|
// Call createERC20 token function of the contract
|
||||||
const trxReceipt = await nftContract.methods
|
const trxReceipt = await nftContract.methods
|
||||||
@ -93,7 +95,12 @@ export class Nft extends SmartContract {
|
|||||||
* @param {String} manager User adress which is going to be assing manager
|
* @param {String} manager User adress which is going to be assing manager
|
||||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||||
*/
|
*/
|
||||||
public async addManager(nftAddress: string, address: string, manager: string) {
|
public async addManager<G extends boolean = false>(
|
||||||
|
nftAddress: string,
|
||||||
|
address: string,
|
||||||
|
manager: string,
|
||||||
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const nftContract = this.getContract(nftAddress)
|
const nftContract = this.getContract(nftAddress)
|
||||||
|
|
||||||
if ((await this.getNftOwner(nftAddress)) !== address) {
|
if ((await this.getNftOwner(nftAddress)) !== address) {
|
||||||
@ -105,6 +112,7 @@ export class Nft extends SmartContract {
|
|||||||
nftContract.methods.addManager,
|
nftContract.methods.addManager,
|
||||||
manager
|
manager
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Invoke addManager function of the contract
|
// Invoke addManager function of the contract
|
||||||
const trxReceipt = await nftContract.methods.addManager(manager).send({
|
const trxReceipt = await nftContract.methods.addManager(manager).send({
|
||||||
@ -123,7 +131,12 @@ export class Nft extends SmartContract {
|
|||||||
* @param {String} manager User adress which is going to be removed as manager
|
* @param {String} manager User adress which is going to be removed as manager
|
||||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||||
*/
|
*/
|
||||||
public async removeManager(nftAddress: string, address: string, manager: string) {
|
public async removeManager<G extends boolean = false>(
|
||||||
|
nftAddress: string,
|
||||||
|
address: string,
|
||||||
|
manager: string,
|
||||||
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const nftContract = this.getContract(nftAddress)
|
const nftContract = this.getContract(nftAddress)
|
||||||
|
|
||||||
if ((await this.getNftOwner(nftAddress)) !== address) {
|
if ((await this.getNftOwner(nftAddress)) !== address) {
|
||||||
@ -135,6 +148,7 @@ export class Nft extends SmartContract {
|
|||||||
nftContract.methods.removeManager,
|
nftContract.methods.removeManager,
|
||||||
manager
|
manager
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Invoke removeManager function of the contract
|
// Invoke removeManager function of the contract
|
||||||
const trxReceipt = await nftContract.methods.removeManager(manager).send({
|
const trxReceipt = await nftContract.methods.removeManager(manager).send({
|
||||||
@ -153,11 +167,12 @@ export class Nft extends SmartContract {
|
|||||||
* @param {String} datatokenDeployer User adress which is going to have DatatokenDeployer permission
|
* @param {String} datatokenDeployer User adress which is going to have DatatokenDeployer permission
|
||||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||||
*/
|
*/
|
||||||
public async addDatatokenDeployer(
|
public async addDatatokenDeployer<G extends boolean = false>(
|
||||||
nftAddress: string,
|
nftAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
datatokenDeployer: string
|
datatokenDeployer: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const nftContract = this.getContract(nftAddress)
|
const nftContract = this.getContract(nftAddress)
|
||||||
|
|
||||||
if ((await this.getNftPermissions(nftAddress, address)).manager !== true) {
|
if ((await this.getNftPermissions(nftAddress, address)).manager !== true) {
|
||||||
@ -170,6 +185,7 @@ export class Nft extends SmartContract {
|
|||||||
nftContract.methods.addToCreateERC20List,
|
nftContract.methods.addToCreateERC20List,
|
||||||
datatokenDeployer
|
datatokenDeployer
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Invoke addToCreateERC20List function of the contract
|
// Invoke addToCreateERC20List function of the contract
|
||||||
const trxReceipt = await nftContract.methods
|
const trxReceipt = await nftContract.methods
|
||||||
@ -190,11 +206,12 @@ export class Nft extends SmartContract {
|
|||||||
* @param {String} datatokenDeployer Address of the user to be revoked DatatokenDeployer Permission
|
* @param {String} datatokenDeployer Address of the user to be revoked DatatokenDeployer Permission
|
||||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||||
*/
|
*/
|
||||||
public async removeDatatokenDeployer(
|
public async removeDatatokenDeployer<G extends boolean = false>(
|
||||||
nftAddress: string,
|
nftAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
datatokenDeployer: string
|
datatokenDeployer: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const nftContract = this.getContract(nftAddress)
|
const nftContract = this.getContract(nftAddress)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -209,6 +226,7 @@ export class Nft extends SmartContract {
|
|||||||
nftContract.methods.removeFromCreateERC20List,
|
nftContract.methods.removeFromCreateERC20List,
|
||||||
datatokenDeployer
|
datatokenDeployer
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call removeFromCreateERC20List function of the contract
|
// Call removeFromCreateERC20List function of the contract
|
||||||
const trxReceipt = await nftContract.methods
|
const trxReceipt = await nftContract.methods
|
||||||
@ -229,11 +247,12 @@ export class Nft extends SmartContract {
|
|||||||
* @param {String} metadataUpdater User adress which is going to have Metadata Updater permission
|
* @param {String} metadataUpdater User adress which is going to have Metadata Updater permission
|
||||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||||
*/
|
*/
|
||||||
public async addMetadataUpdater(
|
public async addMetadataUpdater<G extends boolean = false>(
|
||||||
nftAddress: string,
|
nftAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
metadataUpdater: string
|
metadataUpdater: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const nftContract = this.getContract(nftAddress)
|
const nftContract = this.getContract(nftAddress)
|
||||||
|
|
||||||
if ((await this.getNftPermissions(nftAddress, address)).manager !== true) {
|
if ((await this.getNftPermissions(nftAddress, address)).manager !== true) {
|
||||||
@ -245,6 +264,7 @@ export class Nft extends SmartContract {
|
|||||||
nftContract.methods.addToMetadataList,
|
nftContract.methods.addToMetadataList,
|
||||||
metadataUpdater
|
metadataUpdater
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call addToMetadataList function of the contract
|
// Call addToMetadataList function of the contract
|
||||||
const trxReceipt = await nftContract.methods.addToMetadataList(metadataUpdater).send({
|
const trxReceipt = await nftContract.methods.addToMetadataList(metadataUpdater).send({
|
||||||
@ -256,29 +276,6 @@ export class Nft extends SmartContract {
|
|||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Estimate gas cost for removeFromMetadataList method
|
|
||||||
* @param {String} nftAddress NFT contract address
|
|
||||||
* @param {String} address NFT Manager adress
|
|
||||||
* @param {String} metadataUpdater Address of the user to be revoked Metadata updater Permission
|
|
||||||
* @param {Contract} nftContract optional contract instance
|
|
||||||
* @return {Promise<any>}
|
|
||||||
*/
|
|
||||||
public async esGasRemoveMetadataUpdater(
|
|
||||||
nftAddress: string,
|
|
||||||
address: string,
|
|
||||||
metadataUpdater: string,
|
|
||||||
contractInstance?: Contract
|
|
||||||
): Promise<any> {
|
|
||||||
const nftContract = contractInstance || this.getContract(nftAddress)
|
|
||||||
|
|
||||||
return calculateEstimatedGas(
|
|
||||||
address,
|
|
||||||
nftContract.methods.removeFromMetadataList,
|
|
||||||
metadataUpdater
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove Metadata Updater permission - only Manager can succeed
|
* Remove Metadata Updater permission - only Manager can succeed
|
||||||
* @param {String} nftAddress NFT contract address
|
* @param {String} nftAddress NFT contract address
|
||||||
@ -286,11 +283,12 @@ export class Nft extends SmartContract {
|
|||||||
* @param {String} metadataUpdater Address of the user to be revoked Metadata updater Permission
|
* @param {String} metadataUpdater Address of the user to be revoked Metadata updater Permission
|
||||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||||
*/
|
*/
|
||||||
public async removeMetadataUpdater(
|
public async removeMetadataUpdater<G extends boolean = false>(
|
||||||
nftAddress: string,
|
nftAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
metadataUpdater: string
|
metadataUpdater: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const nftContract = this.getContract(nftAddress)
|
const nftContract = this.getContract(nftAddress)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -301,12 +299,12 @@ export class Nft extends SmartContract {
|
|||||||
throw new Error(`Caller is not Manager nor Metadata Updater`)
|
throw new Error(`Caller is not Manager nor Metadata Updater`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.esGasRemoveMetadataUpdater(
|
const estGas = await calculateEstimatedGas(
|
||||||
nftAddress,
|
|
||||||
address,
|
address,
|
||||||
metadataUpdater,
|
nftContract.methods.removeFromMetadataList,
|
||||||
nftContract
|
metadataUpdater
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call removeFromMetadataList function of the contract
|
// Call removeFromMetadataList function of the contract
|
||||||
const trxReceipt = await nftContract.methods
|
const trxReceipt = await nftContract.methods
|
||||||
@ -327,11 +325,12 @@ export class Nft extends SmartContract {
|
|||||||
* @param {String} storeUpdater User adress which is going to have Store Updater permission
|
* @param {String} storeUpdater User adress which is going to have Store Updater permission
|
||||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||||
*/
|
*/
|
||||||
public async addStoreUpdater(
|
public async addStoreUpdater<G extends boolean = false>(
|
||||||
nftAddress: string,
|
nftAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
storeUpdater: string
|
storeUpdater: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const nftContract = this.getContract(nftAddress)
|
const nftContract = this.getContract(nftAddress)
|
||||||
|
|
||||||
if ((await this.getNftPermissions(nftAddress, address)).manager !== true) {
|
if ((await this.getNftPermissions(nftAddress, address)).manager !== true) {
|
||||||
@ -343,6 +342,7 @@ export class Nft extends SmartContract {
|
|||||||
nftContract.methods.addTo725StoreList,
|
nftContract.methods.addTo725StoreList,
|
||||||
storeUpdater
|
storeUpdater
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call addTo725StoreList function of the contract
|
// Call addTo725StoreList function of the contract
|
||||||
const trxReceipt = await nftContract.methods.addTo725StoreList(storeUpdater).send({
|
const trxReceipt = await nftContract.methods.addTo725StoreList(storeUpdater).send({
|
||||||
@ -361,11 +361,12 @@ export class Nft extends SmartContract {
|
|||||||
* @param {String} storeUpdater Address of the user to be revoked Store Updater Permission
|
* @param {String} storeUpdater Address of the user to be revoked Store Updater Permission
|
||||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||||
*/
|
*/
|
||||||
public async removeStoreUpdater(
|
public async removeStoreUpdater<G extends boolean = false>(
|
||||||
nftAddress: string,
|
nftAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
storeUpdater: string
|
storeUpdater: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const nftContract = this.getContract(nftAddress)
|
const nftContract = this.getContract(nftAddress)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -381,6 +382,7 @@ export class Nft extends SmartContract {
|
|||||||
nftContract.methods.removeFrom725StoreList,
|
nftContract.methods.removeFrom725StoreList,
|
||||||
storeUpdater
|
storeUpdater
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call removeFrom725StoreList function of the contract
|
// Call removeFrom725StoreList function of the contract
|
||||||
const trxReceipt = await nftContract.methods
|
const trxReceipt = await nftContract.methods
|
||||||
@ -404,10 +406,11 @@ export class Nft extends SmartContract {
|
|||||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public async cleanPermissions(
|
public async cleanPermissions<G extends boolean = false>(
|
||||||
nftAddress: string,
|
nftAddress: string,
|
||||||
address: string
|
address: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const nftContract = this.getContract(nftAddress)
|
const nftContract = this.getContract(nftAddress)
|
||||||
|
|
||||||
if ((await this.getNftOwner(nftAddress)) !== address) {
|
if ((await this.getNftOwner(nftAddress)) !== address) {
|
||||||
@ -418,6 +421,7 @@ export class Nft extends SmartContract {
|
|||||||
address,
|
address,
|
||||||
nftContract.methods.cleanPermissions
|
nftContract.methods.cleanPermissions
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call cleanPermissions function of the contract
|
// Call cleanPermissions function of the contract
|
||||||
const trxReceipt = await nftContract.methods.cleanPermissions().send({
|
const trxReceipt = await nftContract.methods.cleanPermissions().send({
|
||||||
@ -438,12 +442,13 @@ export class Nft extends SmartContract {
|
|||||||
* @param {Number} tokenId The id of the token to be transfered
|
* @param {Number} tokenId The id of the token to be transfered
|
||||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||||
*/
|
*/
|
||||||
public async transferNft(
|
public async transferNft<G extends boolean = false>(
|
||||||
nftAddress: string,
|
nftAddress: string,
|
||||||
nftOwner: string,
|
nftOwner: string,
|
||||||
nftReceiver: string,
|
nftReceiver: string,
|
||||||
tokenId?: number
|
tokenId?: number,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const nftContract = this.getContract(nftAddress)
|
const nftContract = this.getContract(nftAddress)
|
||||||
|
|
||||||
if ((await this.getNftOwner(nftAddress)) !== nftOwner) {
|
if ((await this.getNftOwner(nftAddress)) !== nftOwner) {
|
||||||
@ -459,6 +464,7 @@ export class Nft extends SmartContract {
|
|||||||
nftReceiver,
|
nftReceiver,
|
||||||
tokenIdentifier
|
tokenIdentifier
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call transferFrom function of the contract
|
// Call transferFrom function of the contract
|
||||||
const trxReceipt = await nftContract.methods
|
const trxReceipt = await nftContract.methods
|
||||||
@ -481,12 +487,13 @@ export class Nft extends SmartContract {
|
|||||||
* @param {Number} tokenId The id of the token to be transfered
|
* @param {Number} tokenId The id of the token to be transfered
|
||||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||||
*/
|
*/
|
||||||
public async safeTransferNft(
|
public async safeTransferNft<G extends boolean = false>(
|
||||||
nftAddress: string,
|
nftAddress: string,
|
||||||
nftOwner: string,
|
nftOwner: string,
|
||||||
nftReceiver: string,
|
nftReceiver: string,
|
||||||
tokenId?: number
|
tokenId?: number,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const nftContract = this.getContract(nftAddress)
|
const nftContract = this.getContract(nftAddress)
|
||||||
|
|
||||||
if ((await this.getNftOwner(nftAddress)) !== nftOwner) {
|
if ((await this.getNftOwner(nftAddress)) !== nftOwner) {
|
||||||
@ -502,6 +509,7 @@ export class Nft extends SmartContract {
|
|||||||
nftReceiver,
|
nftReceiver,
|
||||||
tokenIdentifier
|
tokenIdentifier
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call transferFrom function of the contract
|
// Call transferFrom function of the contract
|
||||||
const trxReceipt = await nftContract.methods
|
const trxReceipt = await nftContract.methods
|
||||||
@ -522,7 +530,7 @@ export class Nft extends SmartContract {
|
|||||||
* @param {String} address Caller address NFT Owner adress
|
* @param {String} address Caller address NFT Owner adress
|
||||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||||
*/
|
*/
|
||||||
public async setMetadata(
|
public async setMetadata<G extends boolean = false>(
|
||||||
nftAddress: string,
|
nftAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
metadataState: number,
|
metadataState: number,
|
||||||
@ -531,8 +539,9 @@ export class Nft extends SmartContract {
|
|||||||
flags: string,
|
flags: string,
|
||||||
data: string,
|
data: string,
|
||||||
metadataHash: string,
|
metadataHash: string,
|
||||||
metadataProofs?: MetadataProof[]
|
metadataProofs?: MetadataProof[],
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const nftContract = this.getContract(nftAddress)
|
const nftContract = this.getContract(nftAddress)
|
||||||
if (!metadataProofs) metadataProofs = []
|
if (!metadataProofs) metadataProofs = []
|
||||||
if (!(await this.getNftPermissions(nftAddress, address)).updateMetadata) {
|
if (!(await this.getNftPermissions(nftAddress, address)).updateMetadata) {
|
||||||
@ -549,6 +558,8 @@ export class Nft extends SmartContract {
|
|||||||
metadataHash,
|
metadataHash,
|
||||||
metadataProofs
|
metadataProofs
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
const trxReceipt = await nftContract.methods
|
const trxReceipt = await nftContract.methods
|
||||||
.setMetaData(
|
.setMetaData(
|
||||||
metadataState,
|
metadataState,
|
||||||
@ -575,11 +586,12 @@ export class Nft extends SmartContract {
|
|||||||
* @param {MetadataAndTokenURI} metadataAndTokenURI metaDataAndTokenURI object
|
* @param {MetadataAndTokenURI} metadataAndTokenURI metaDataAndTokenURI object
|
||||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||||
*/
|
*/
|
||||||
public async setMetadataAndTokenURI(
|
public async setMetadataAndTokenURI<G extends boolean = false>(
|
||||||
nftAddress: string,
|
nftAddress: string,
|
||||||
metadataUpdater: string,
|
metadataUpdater: string,
|
||||||
metadataAndTokenURI: MetadataAndTokenURI
|
metadataAndTokenURI: MetadataAndTokenURI,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const nftContract = this.getContract(nftAddress)
|
const nftContract = this.getContract(nftAddress)
|
||||||
if (!(await this.getNftPermissions(nftAddress, metadataUpdater)).updateMetadata) {
|
if (!(await this.getNftPermissions(nftAddress, metadataUpdater)).updateMetadata) {
|
||||||
throw new Error(`Caller is not Metadata updater`)
|
throw new Error(`Caller is not Metadata updater`)
|
||||||
@ -593,6 +605,8 @@ export class Nft extends SmartContract {
|
|||||||
nftContract.methods.setMetaDataAndTokenURI,
|
nftContract.methods.setMetaDataAndTokenURI,
|
||||||
sanitizedMetadataAndTokenURI
|
sanitizedMetadataAndTokenURI
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
const trxReceipt = await nftContract.methods
|
const trxReceipt = await nftContract.methods
|
||||||
.setMetaDataAndTokenURI(sanitizedMetadataAndTokenURI)
|
.setMetaDataAndTokenURI(sanitizedMetadataAndTokenURI)
|
||||||
.send({
|
.send({
|
||||||
@ -611,11 +625,12 @@ export class Nft extends SmartContract {
|
|||||||
* @param {Number} metadataState new metadata state
|
* @param {Number} metadataState new metadata state
|
||||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||||
*/
|
*/
|
||||||
public async setMetadataState(
|
public async setMetadataState<G extends boolean = false>(
|
||||||
nftAddress: string,
|
nftAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
metadataState: number
|
metadataState: number,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const nftContract = this.getContract(nftAddress)
|
const nftContract = this.getContract(nftAddress)
|
||||||
|
|
||||||
if (!(await this.getNftPermissions(nftAddress, address)).updateMetadata) {
|
if (!(await this.getNftPermissions(nftAddress, address)).updateMetadata) {
|
||||||
@ -627,6 +642,7 @@ export class Nft extends SmartContract {
|
|||||||
nftContract.methods.setMetaDataState,
|
nftContract.methods.setMetaDataState,
|
||||||
metadataState
|
metadataState
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call transferFrom function of the contract
|
// Call transferFrom function of the contract
|
||||||
const trxReceipt = await nftContract.methods.setMetaDataState(metadataState).send({
|
const trxReceipt = await nftContract.methods.setMetaDataState(metadataState).send({
|
||||||
@ -644,11 +660,12 @@ export class Nft extends SmartContract {
|
|||||||
* @param data input data for TokenURI
|
* @param data input data for TokenURI
|
||||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||||
*/
|
*/
|
||||||
public async setTokenURI(
|
public async setTokenURI<G extends boolean = false>(
|
||||||
nftAddress: string,
|
nftAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
data: string
|
data: string,
|
||||||
): Promise<any> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const nftContract = this.getContract(nftAddress)
|
const nftContract = this.getContract(nftAddress)
|
||||||
|
|
||||||
const estGas = await calculateEstimatedGas(
|
const estGas = await calculateEstimatedGas(
|
||||||
@ -657,6 +674,8 @@ export class Nft extends SmartContract {
|
|||||||
'1',
|
'1',
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
const trxReceipt = await nftContract.methods.setTokenURI('1', data).send({
|
const trxReceipt = await nftContract.methods.setTokenURI('1', data).send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user