@evolutionland/evolution-js
Version:
evolution evolution-js evolutionland evolution-js-sdk evolution-land metaverse
171 lines (133 loc) • 12 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>erc721/index.ts - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<script src="scripts/nav.js" defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav >
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#apostleAllowanceToClockAuction">apostleAllowanceToClockAuction</a></li><li><a href="global.html#apostleAskWithToken">apostleAskWithToken</a></li><li><a href="global.html#apostleBidWithToken">apostleBidWithToken</a></li><li><a href="global.html#apostleBorn">apostleBorn</a></li><li><a href="global.html#apostleBornAndEnhance">apostleBornAndEnhance</a></li><li><a href="global.html#apostleBreed">apostleBreed</a></li><li><a href="global.html#apostleBreedAsk">apostleBreedAsk</a></li><li><a href="global.html#apostleBreedBid">apostleBreedBid</a></li><li><a href="global.html#apostleCancelAskWithToken">apostleCancelAskWithToken</a></li><li><a href="global.html#apostleCancelBreedAsk">apostleCancelBreedAsk</a></li><li><a href="global.html#apostleCancelHire">apostleCancelHire</a></li><li><a href="global.html#apostleClaim">apostleClaim</a></li><li><a href="global.html#apostleClaimHire">apostleClaimHire</a></li><li><a href="global.html#apostleGetAutoBreedFee">apostleGetAutoBreedFee</a></li><li><a href="global.html#apostleGetCurrentPriceByTokenId">apostleGetCurrentPriceByTokenId</a></li><li><a href="global.html#apostleGetCurrentSiringPriceByTokenId">apostleGetCurrentSiringPriceByTokenId</a></li><li><a href="global.html#apostleHire">apostleHire</a></li><li><a href="global.html#apostleHireBid">apostleHireBid</a></li><li><a href="global.html#apostleStopWork">apostleStopWork</a></li><li><a href="global.html#apostleTransfer">apostleTransfer</a></li><li><a href="global.html#apostleWork">apostleWork</a></li><li><a href="global.html#drillStopWork">drillStopWork</a></li><li><a href="global.html#drillTransfer">drillTransfer</a></li><li><a href="global.html#drillWork">drillWork</a></li><li><a href="global.html#equipmentTransfer">equipmentTransfer</a></li><li><a href="global.html#equipmentUnequip">equipmentUnequip</a></li><li><a href="global.html#erc20Allowance">erc20Allowance</a></li><li><a href="global.html#erc20AllowanceByContractAddress">erc20AllowanceByContractAddress</a></li><li><a href="global.html#erc20Approve">erc20Approve</a></li><li><a href="global.html#erc20ApproveByContractAddress">erc20ApproveByContractAddress</a></li><li><a href="global.html#erc20BalanceOf">erc20BalanceOf</a></li><li><a href="global.html#erc20TotalSupply">erc20TotalSupply</a></li><li><a href="global.html#erc20TransferByContractAddress">erc20TransferByContractAddress</a></li><li><a href="global.html#erc721IsApprovedForAll">erc721IsApprovedForAll</a></li><li><a href="global.html#erc721IsApprovedOrOwner">erc721IsApprovedOrOwner</a></li><li><a href="global.html#erc721OwnerOf">erc721OwnerOf</a></li><li><a href="global.html#erc721SetApprovalForAll">erc721SetApprovalForAll</a></li><li><a href="global.html#erc1155BalanceOf">erc1155BalanceOf</a></li><li><a href="global.html#erc1155BalanceOfBatch">erc1155BalanceOfBatch</a></li><li><a href="global.html#erc1155IsApprovedForAll">erc1155IsApprovedForAll</a></li><li><a href="global.html#erc1155SafeBatchTransferFrom">erc1155SafeBatchTransferFrom</a></li><li><a href="global.html#erc1155SetApprovalForAll">erc1155SetApprovalForAll</a></li><li><a href="global.html#farmGetStakerAddress">farmGetStakerAddress</a></li><li><a href="global.html#farmGetStakerBalanceOf">farmGetStakerBalanceOf</a></li><li><a href="global.html#farmGetStakerEarned">farmGetStakerEarned</a></li><li><a href="global.html#farmGetStakerExit">farmGetStakerExit</a></li><li><a href="global.html#farmGetStakerGetReward">farmGetStakerGetReward</a></li><li><a href="global.html#farmGetStakerStakeToken">farmGetStakerStakeToken</a></li><li><a href="global.html#farmGetStakerTotalSupply">farmGetStakerTotalSupply</a></li><li><a href="global.html#farmStakerWithdraw">farmStakerWithdraw</a></li><li><a href="global.html#furnaceBuyTreasure">furnaceBuyTreasure</a></li><li><a href="global.html#furnaceDisenchantProps">furnaceDisenchantProps</a></li><li><a href="global.html#furnaceDismantleEquipment">furnaceDismantleEquipment</a></li><li><a href="global.html#furnaceEnchantEquipment">furnaceEnchantEquipment</a></li><li><a href="global.html#furnaceEnchantProps">furnaceEnchantProps</a></li><li><a href="global.html#furnaceGetTreasurePrice">furnaceGetTreasurePrice</a></li><li><a href="global.html#furnaceGetTreasureStatus">furnaceGetTreasureStatus</a></li><li><a href="global.html#furnaceOpenTreasure">furnaceOpenTreasure</a></li><li><a href="global.html#goldRushRaffleChangeAmount">goldRushRaffleChangeAmount</a></li><li><a href="global.html#goldRushRaffleChangeInfo">goldRushRaffleChangeInfo</a></li><li><a href="global.html#goldRushRaffleChangeSubAddr">goldRushRaffleChangeSubAddr</a></li><li><a href="global.html#goldRushRaffleDraw">goldRushRaffleDraw</a></li><li><a href="global.html#goldRushRaffleExit">goldRushRaffleExit</a></li><li><a href="global.html#goldRushRaffleGetHistory">goldRushRaffleGetHistory</a></li><li><a href="global.html#goldRushRaffleJoin">goldRushRaffleJoin</a></li><li><a href="global.html#landAskWithToken">landAskWithToken</a></li><li><a href="global.html#landBatchClaimItemResource">landBatchClaimItemResource</a></li><li><a href="global.html#landBatchClaimLandResource">landBatchClaimLandResource</a></li><li><a href="global.html#landBidWithToken">landBidWithToken</a></li><li><a href="global.html#landCancelAskWithToken">landCancelAskWithToken</a></li><li><a href="global.html#landClaimItemResource">landClaimItemResource</a></li><li><a href="global.html#landClaimLand">landClaimLand</a></li><li><a href="global.html#landGetAvailableItemResources">landGetAvailableItemResources</a></li><li><a href="global.html#landGetAvailableResources">landGetAvailableResources</a></li><li><a href="global.html#landGetCurrentPriceByTokenId">landGetCurrentPriceByTokenId</a></li><li><a href="global.html#landTransfer">landTransfer</a></li><li><a href="global.html#lotteryGetPointsBalance">lotteryGetPointsBalance</a></li><li><a href="global.html#lotteryGetTotalRewardInPool">lotteryGetTotalRewardInPool</a></li><li><a href="global.html#lotteryPlayWithTicket">lotteryPlayWithTicket</a></li><li><a href="global.html#materialBalanceOfBatch">materialBalanceOfBatch</a></li><li><a href="global.html#materialBatchTransfer">materialBatchTransfer</a></li><li><a href="global.html#materialIdEncode">materialIdEncode</a></li><li><a href="global.html#pveTeamAt">pveTeamAt</a></li><li><a href="global.html#pveTeamEvict">pveTeamEvict</a></li><li><a href="global.html#pveTeamExist">pveTeamExist</a></li><li><a href="global.html#pveTeamExit">pveTeamExit</a></li><li><a href="global.html#pveTeamExits">pveTeamExits</a></li><li><a href="global.html#pveTeamJoin">pveTeamJoin</a></li><li><a href="global.html#pveTeamJoins">pveTeamJoins</a></li><li><a href="global.html#pveTeamSwap">pveTeamSwap</a></li><li><a href="global.html#uniswapBuyRING">uniswapBuyRING</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">erc721/index.ts</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import { ethers } from "ethers";
import { getAbiObjectOwnership, getAbiERC721, getAbiERC721Collection } from "@evo/utils/ethers/abiHelper";
import type { CallbackType } from "@evo/utils/ethers/contractHelper";
import { pad0xBegin } from "@evo/utils/common/utils";
import { triggerContract, viewContract, getContract } from "@evo/utils/ethers/contractHelper";
import { TransactionResponse } from "@ethersproject/providers";
/**
* ERC721 Owner of
* @param provider Provider
* @param tokenAddress ERC721 contract address
* @param tokenId Token Id
* @param callback Callback
* @returns The address of owner
*/
export const erc721OwnerOf = async (
provider: ethers.providers.Provider,
tokenAddress: string,
tokenId: string,
callback?: CallbackType
): Promise<string> => {
const contract = await getContract(provider, tokenAddress, await getAbiObjectOwnership());
const results = await viewContract(contract, "ownerOf", [tokenId], callback);
return results.length ? results[0] : "";
};
/**
* Query if an address is an authorized operator for another address
* @param provider Provider
* @param owner The address that owns the NFTs
* @param spender The address that acts on behalf of the owner
* @param tokenContractAddress ERC721 contract address
* @param callback Callback
* @returns any
*/
export const erc721IsApprovedForAll = async (
provider: ethers.providers.Provider,
owner: string,
spender: string,
tokenContractAddress: string,
callback?: CallbackType
): Promise<boolean> => {
const contract = await getContract(provider, tokenContractAddress, await getAbiERC721Collection());
const results = await viewContract(contract, "isApprovedForAll", [owner, spender]);
return results.length ? results[0] : false;
};
/**
* Returns whether `spender` is allowed to manage `tokenId`.
* @param provider Provider
* @param spender The address that acts on behalf of the owner
* @param tokenContractAddress The factory of tokenId.
* @param tokenId ERC721 token Id;
* @param callback Callback
* @returns any
*/
export const erc721IsApprovedOrOwner = async (
provider: ethers.providers.Provider,
spender: string,
tokenContractAddress: string,
tokenId: string,
callback?: CallbackType
): Promise<boolean> => {
const contract = await getContract(provider, tokenContractAddress, await getAbiERC721());
const owner = await viewContract(contract, "ownerOf", [pad0xBegin(tokenId)]);
if (!owner._owner) {
throw new Error("erc721IsApprovedOrOwner::Token Id does not exist!");
}
const approvedAddress = await viewContract(contract, "getApproved", [pad0xBegin(tokenId)]);
const isApprovedForAll = await erc721IsApprovedForAll(provider, owner._owner, spender, tokenContractAddress);
return (
owner._owner?.toLowerCase() === spender.toLowerCase() ||
approvedAddress._approved?.toLowerCase() === spender.toLowerCase() ||
isApprovedForAll
);
};
/**
* Change or reaffirm the approved address for all of NFT
* @param signer Signer
* @param contractAddress The factory of tokenId.
* @param spender The address that acts on behalf of the owner
* @param approved Approved or Cancel Approved
* @param callback Callback
* @returns any
*/
export const erc721SetApprovalForAll = async (
signer: ethers.Signer,
contractAddress: string,
spender: string,
approved: boolean,
callback?: CallbackType
): Promise<TransactionResponse> => {
const contract = await getContract(signer, contractAddress, await getAbiERC721Collection());
return triggerContract(contract, "setApprovalForAll", [spender, approved], callback);
};
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Mon Aug 15 2022 13:54:57 GMT+0800 (China Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>
</body>
</html>