Skip to content

Commit

Permalink
Create TokenizedAssets.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 8, 2024
1 parent add2cb7 commit cd071cb
Showing 1 changed file with 51 additions and 0 deletions.
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;
}
}

0 comments on commit cd071cb

Please sign in to comment.