修改mint nft类型的task

This commit is contained in:
zhl 2023-04-23 11:47:49 +08:00
parent 4e2cefbba4
commit 63051447c8
2 changed files with 12 additions and 7 deletions

View File

@ -80,7 +80,11 @@ export class BlockChain {
break
case TaskType.MINT_NFT:
reqData.tokenId = reqData.tokenId || reqData.tokenid
abi = await this.erc721Reactor.mint(reqData)
if (reqData.tokenId && !reqData.amount) {
abi = await this.erc721Reactor.mint(reqData)
} else {
abi = await this.erc721Reactor.batchMint(reqData)
}
break
case TaskType.TRANSFER_FT:
abi = await this.erc20Reactor.transfer(reqData)

View File

@ -340,30 +340,31 @@ export class ERC721Reactor {
return contract.methods.mint(to, tokenId).encodeABI()
}
let gas = await contract.methods.mint(to, tokenId).estimateGas({ gas: 1000000 })
return contract.methods.mint(to, tokenId).send({ gas: (gas * 1.1) | 0 })
return contract.methods.mint(to, tokenId).send({ gas: gas | 0 })
}
async batchMint({
account,
address,
to,
tokenIds,
count,
encodeABI = false,
}: {
account?: string
address?: string
to: string
tokenIds: string[]
count: number
encodeABI?: boolean
}) {
const contract = address
? new this.web3.eth.Contract(abiNft, address, { from: account || this.account.address })
: this.contract
// let gas = await contract.methods.batchMint(to, tokenIds, configIds).estimateGas({ gas: 1000000 })
const countStr = count + ''
if (encodeABI) {
return contract.methods.batchMint(to, tokenIds).encodeABI()
return contract.methods.batchMint(to, countStr).encodeABI()
}
return contract.methods.batchMint(to, tokenIds).send({ gas: 1000000 })
let gas = await contract.methods.batchMint(to, countStr).estimateGas({ from: account || this.account.address })
return contract.methods.batchMint(to, countStr).send({ gas: gas | 0 })
}
async getPastEvents({ address, fromBlock }: { address?: string; fromBlock: number }) {