Created
August 18, 2021 15:14
-
-
Save saadSarwar28/9d4c1771d9cba4236f8de04ef68c68c6 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.4+commit.c7e474f2.js&optimize=false&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.7.0 <0.9.0; | |
/** | |
* @title Ownership | |
* check Ownership of nfts | |
*/ | |
interface deployedContract { | |
function totalSupply() external view returns (uint); | |
function ownerOf(uint tokenId)external view returns (address); | |
function balanceOf(address owner) external view returns(uint); | |
} | |
contract Ownership { | |
function checkOwnership(address walletAddress, address contractAddress) public returns (uint[] memory){ | |
// getting total supply of the contract | |
uint256 totalSupply = getTotalSupply(contractAddress); | |
// getting total number of nfts owned by an address | |
uint balance = getBalanceOf(contractAddress, walletAddress); | |
// initializing an array with the size of total number of nfts owned by an address. | |
uint[] memory ids = new uint[](balance); | |
// iterating through the total number of nfts present in contract | |
for (uint id = 0; id <= totalSupply; totalSupply++) { | |
// contracts whose owner is the given address are added to the array to be returned. | |
if (walletAddress == deployedContract(contractAddress).ownerOf(id)) { | |
for (uint index = 0; index < balance; index++) { | |
if (ids[index] == 0) { | |
ids[index] = id; | |
break; | |
} | |
} | |
} | |
} | |
return ids; | |
} | |
function getTotalSupply(address contractAddress) internal returns(uint256) { | |
return deployedContract(contractAddress).totalSupply(); | |
} | |
function getBalanceOf(address contractAddress, address owner) internal returns(uint256) { | |
return deployedContract(contractAddress).balanceOf(owner); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment