-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
pi-nexus-smart-contracts/binance-smart-chain/contracts/TokenizedAssets.sol
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/token/ERC721/SafeERC721.sol"; | ||
import "@openzeppelin/contracts/utils/Counters.sol"; | ||
|
||
contract TokenizedAssets { | ||
using Counters for Counters.Counter; | ||
using SafeERC721 for address; | ||
|
||
struct TokenizedAsset { | ||
address owner; | ||
uint256 tokenId; | ||
string uri; | ||
} | ||
|
||
mapping(uint256 => TokenizedAsset) public tokenizedAssets; | ||
Counters.Counter public tokenIdCounter; | ||
|
||
function createTokenizedAsset(string memory uri) public { | ||
require(uri != "", "Invalid URI"); | ||
|
||
TokenizedAsset memory asset; | ||
asset.owner = msg.sender; | ||
asset.tokenId = tokenIdCounter.current(); | ||
asset.uri = uri; | ||
|
||
tokenizedAssets[asset.tokenId] = asset; | ||
tokenIdCounter.increment(); | ||
} | ||
|
||
function transferTokenizedAsset(uint256 tokenId, address to) public { | ||
require(tokenId > 0, "Invalid token ID"); | ||
require(to != address(0), "Invalid recipient address"); | ||
|
||
TokenizedAsset storage asset = tokenizedAssets[tokenId]; | ||
require(asset.owner == msg.sender, "Not the owner of the tokenized asset"); | ||
|
||
asset.owner = to; | ||
} | ||
|
||
function getOwner(uint256 tokenId) public view returns (address) { | ||
TokenizedAsset storage asset = tokenizedAssets[tokenId]; | ||
return asset.owner; | ||
} | ||
|
||
function getURI(uint256 tokenId) public view returns (string memory) { | ||
TokenizedAsset storage asset = tokenizedAssets[tokenId]; | ||
return asset.uri; | ||
} | ||
} |