<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by zarah on Medium]]></title>
        <description><![CDATA[Stories by zarah on Medium]]></description>
        <link>https://medium.com/@devvick230385?source=rss-ef368f718606------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*98XfRoFecTMRMRvM</url>
            <title>Stories by zarah on Medium</title>
            <link>https://medium.com/@devvick230385?source=rss-ef368f718606------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 09:57:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@devvick230385/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Detailed Overview of ERC721 Tokens]]></title>
            <link>https://medium.com/@devvick230385/a-detailed-overview-of-erc721-tokens-0f3db96982e8?source=rss-ef368f718606------2</link>
            <guid isPermaLink="false">https://medium.com/p/0f3db96982e8</guid>
            <dc:creator><![CDATA[zarah]]></dc:creator>
            <pubDate>Fri, 16 Feb 2024 13:43:36 GMT</pubDate>
            <atom:updated>2024-02-20T12:41:56.784Z</atom:updated>
            <content:encoded><![CDATA[<p>The idea of non-fungible tokens (NFTs) has become quite popular in the field of blockchain technology, creating new opportunities for digital ownership and innovation. ERC-721 is a potent mechanism for generating distinct, indivisible assets on the Ethereum blockchain among the many NFT standards. This post will explain ERC-721 tokens in detail, go over some of its main characteristics, and provide you some code snippets to help you build and use them.</p><h3>Understanding ERC-721 Tokens</h3><p>ERC-721 is a standard interface for creating non-fungible tokens on the Ethereum blockchain. Unlike cryptocurrencies such as Ether (ETH) or fungible tokens like ERC-20, ERC-721 tokens are unique and indivisible. Each ERC-721 token represents a distinct asset or item, making them ideal for representing ownership of digital or physical assets such as artwork, collectibles, virtual real estate, and in-game items.</p><h3>ERC-721 Interface</h3><p>To create an ERC-721-compliant contract, you need to implement the following functions defined in the ERC-721 interface:</p><pre>interface IERC721 {<br>    function balanceOf(address owner) external view returns (uint256 balance);<br>    function ownerOf(uint256 tokenId) external view returns (address owner);<br>    function safeTransferFrom(address from, address to, uint256 tokenId) external;<br>    function transferFrom(address from, address to, uint256 tokenId) external;<br>    function approve(address to, uint256 tokenId) external;<br>    function getApproved(uint256 tokenId) external view returns (address operator);<br>    function setApprovalForAll(address operator, bool _approved) external;<br>    function isApprovedForAll(address owner, address operator) external view returns (bool);<br>    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);<br>    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);<br>    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);<br>}</pre><p>Now, let’s delve into each function defined in the ERC-721 interface and understand its role in the ERC-721 token ecosystem:</p><p><strong>balanceOf:</strong></p><ul><li>This function determines how many ERC-721 tokens are owned by a specific address. For instance, if you want to know how many tokens Alice owns, you’d call balanceOf(Alice).</li></ul><pre>function balanceOf(address owner) public view virtual override returns (uint256) {<br>    require(owner != address(0), &quot;ERC721: balance query for the zero address&quot;);<br>    return _balances[owner];<br>}</pre><p><strong>ownerOf:</strong></p><ul><li>Given a specific ERC-721 token ID, this function returns the address that currently owns that token. For example, if you have token ID 123, ownerOf(123) will return the address of the current owner.</li></ul><pre>function ownerOf(uint256 tokenId) public view virtual override returns (address) {<br>    address owner = _owners[tokenId];<br>    require(owner != address(0), &quot;ERC721: owner query for nonexistent token&quot;);<br>    return owner;<br>}</pre><p><strong>safeTransferFrom:</strong></p><ul><li>safeTransferFrom securely transfers an ERC-721 token from one address to another. It ensures that the recipient can handle receiving the token by calling a function (onERC721Received) in the recipient contract.</li></ul><p><strong>transferFrom:</strong></p><ul><li>Similar to safeTransferFrom, transferFrom moves an ERC-721 token from one address to another. However, it doesn&#39;t include the additional safety checks of safeTransferFrom.</li></ul><p><strong>approve:</strong></p><ul><li>This function allows an ERC-721 token owner to authorize another address to transfer a specific token on their behalf. For instance, Alice can approve Bob to transfer her token ID 123 by calling approve(Bob, 123).</li></ul><pre>function approve(address to, uint256 tokenId) public virtual override {<br>    address owner = ownerOf(tokenId);<br>    require(to != owner, &quot;ERC721: approval to current owner&quot;);<br>    require(_msgSender() == owner || isApprovedForAll(owner, _msgSender()),<br>        &quot;ERC721: approve caller is not owner nor approved for all&quot;<br>    );<br><br>    _approve(to, tokenId);<br>}</pre><p><strong>getApproved:</strong></p><ul><li>Given a token ID, getApproved returns the address that has been granted approval to transfer that token. For example, if Alice approves Bob to transfer her token ID 123, getApproved(123) will return Bob&#39;s address.</li></ul><pre>function getApproved(uint256 tokenId) public view virtual override returns (address) {<br>    require(_exists(tokenId), &quot;ERC721: approved query for nonexistent token&quot;);<br><br>    return _tokenApprovals[tokenId];<br>}</pre><p><strong>setApprovalForAll:</strong></p><ul><li>With setApprovalForAll, a token owner can grant permission to an operator to transfer all of their ERC-721 tokens. This is useful for scenarios like marketplace trading, where an operator needs broader permission.</li></ul><pre>function setApprovalForAll(address operator, bool approved) public virtual override {<br>    require(operator != _msgSender(), &quot;ERC721: approve to caller&quot;);<br>    _operatorApprovals[_msgSender()][operator] = approved;<br>    emit ApprovalForAll(_msgSender(), operator, approved);<br>}</pre><p><strong>isApprovedForAll:</strong></p><ul><li>isApprovedForAll checks if an address is approved to transfer all ERC-721 tokens owned by another address. For instance, if Alice approves Bob as her operator using setApprovalForAll(Bob, true), isApprovedForAll(Alice, Bob) will return true.</li></ul><pre>function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {<br>    return _operatorApprovals[owner][operator];<br>}</pre><p>OpenZeppelin offers a comprehensive suite of functionalities necessary to prepare our ERC721 token. Here’s the code that imports OpenZeppelin:</p><pre>// SPDX-License-Identifier: UNLICENSED<br>pragma solidity ^0.8.20;<br>import &quot;@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol&quot;;<br>import &quot;@openzeppelin/contracts/access/Ownable.sol&quot;;<br><br>contract NFT is ERC721URIStorage, Ownable {<br>    constructor() ERC721(&quot;PydeFT&quot;, &quot;Pyde Token&quot;) Ownable(msg.sender) {}<br><br>    function mint(<br>        address _to,<br>        uint256 _tokenId,<br>        string calldata _tokenUri<br>    ) external onlyOwner {<br>        _mint(_to, _tokenId);<br>        _setTokenURI(_tokenId, _tokenUri);<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0f3db96982e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ERC20 TOKEN]]></title>
            <link>https://medium.com/@devvick230385/erc20-token-pyde-pyper-25b4c5fad4f7?source=rss-ef368f718606------2</link>
            <guid isPermaLink="false">https://medium.com/p/25b4c5fad4f7</guid>
            <dc:creator><![CDATA[zarah]]></dc:creator>
            <pubDate>Thu, 15 Feb 2024 01:23:35 GMT</pubDate>
            <atom:updated>2024-07-04T07:01:31.745Z</atom:updated>
            <content:encoded><![CDATA[<p>ERC-20 is the technical standard for fungible tokens created using the Ethereum blockchain.</p><h3>Data Structures and Variables</h3><p>ERC-20 tokens rely on several key variables to define their behavior and functionality. These variables include the token’s name, symbol, and decimals, which serve as basic identifiers and determine divisibility. Additionally, the total supply parameter establishes scarcity and influences token economics. The balance and allowance mappings facilitate secure token management and transactions, while events such as Transfer and Approval provide transparency and interoperability</p><pre>    uint256 totalSupply;<br>    address immutable owner;<br>    string public constant name = &quot;Pyde Pyper&quot;;<br>    string public constant symbol = &quot;Pyde&quot;;<br>    uint8 immutable decimal;<br>    event Approve(address indexed by, address indexed to, uint256 value);<br>    event Transfer(address indexed from, address indexed to, uint256 value);<br>    mapping(address =&gt; uint256) balance;<br>    mapping(address =&gt; mapping(address =&gt; uint256)) allowance;</pre><h3>Functions</h3><ul><li>Transfer: The transfer function allows token holders to send tokens from their own address to another Ethereum address. This function typically requires two parameters: the recipient&#39;s address and the amount of tokens to transfer.</li></ul><pre>    function transfer(address _recipient, uint256 _amount) external {<br>        require(_amount &gt; 0, &quot;Zero values are not allowed&quot;);<br>        uint256 charge = calculatePercentageCharge(calculateDecimal(_amount));<br>        require(<br>            totalSupply &gt;= calculateDecimal(_amount) + charge,<br>            &quot;Insufficient balance&quot;<br>        );<br>        if(msg.sender == owner){<br>            totalSupply -= (calculateDecimal(_amount)+charge);<br>        }<br>        uint256 _userAvailableBalance = balance[_recipient];<br>        balance[_recipient] = _userAvailableBalance + calculateDecimal(_amount);<br>        balance[msg.sender] =<br>            balance[msg.sender] -<br>            calculateDecimal(_amount) -<br>            charge;<br>    }</pre><ul><li>TransferFrom: The transferFrom function is used for delegated transfers, where one address (the “spender”) is authorized to transfer tokens on behalf of another address (the “owner”). This function is commonly employed in scenarios such as token approvals for decentralized exchanges or token allowances for smart contracts.</li></ul><pre> function transferFrom(<br>        address _from,<br>        address _receiver,<br>        uint256 _amount<br>    ) external {<br>        require(_from != address(0), &quot;Invalid sender address&quot;);<br>        require(_receiver != address(0), &quot;Invalid recipient address&quot;);<br>        require(_amount &gt; 0, &quot;Zero values are not allowed&quot;);<br>        uint256 charge = calculatePercentageCharge(calculateDecimal(_amount));<br>        uint256 _total = calculateDecimal(_amount) + charge;<br>        require(balance[_from] &gt;= _total, &quot;Insufficient balance&quot;);<br>        require(allowance[_from][msg.sender] &gt;= _total, &quot;Allowance exceeded&quot;);<br>        balance[_from] -= _total;<br>        balance[_receiver] += calculateDecimal(_amount);<br>        allowance[_from][msg.sender] -= calculateDecimal(_amount);<br>        emit Transfer(msg.sender, _receiver, _amount);<br>    }</pre><ul><li>Approve: The approve function is utilized to grant approval for a designated spender to transfer a specified amount of tokens from the owner’s address. It allows for flexible token authorization mechanisms, enabling secure and controlled token transfers.</li></ul><pre>  function approve(address _user, uint256 _amount) external {<br>        require(msg.sender != address(0), &quot;Invalid address&quot;);<br>        require(_amount &gt; 0, &quot;Zero values are not allowed&quot;);<br>        require(<br>            _user != address(0),<br>            &quot;Transfers are not allowed to address zero&quot;<br>        );<br>        allowance[msg.sender][_user] = calculateDecimal(_amount);<br>        emit Approve(msg.sender, _user, _amount);<br>    }</pre><ul><li>CalculatePercentageCharge: The calculatePercentageCharge function is a custom function added to the ERC-20 token contract to calculate a 10% charge on any transferred amount. This function is designed to deduct a percentage fee from the transferred amount before the transfer occurs.</li></ul><pre>function calculatePercentageCharge(uint256 _amount) internal pure returns (uint256) {<br>        return (10*_amount)/100; <br>    }</pre><ul><li>Burn: The burn function allows the contract owner to permanently remove a specified amount of tokens from circulation.</li></ul><pre>function burn(uint256 _amount) external {<br>        require(msg.sender == owner, &quot;Only owner has this privilege&quot;);<br>        require(totalSupply&gt;=calculateDecimal(_amount),&quot;Insufficient balance to burn&quot;);<br>        totalSupply -= calculateDecimal(_amount);<br>        balance[owner] -= calculateDecimal(_amount);<br>    }</pre><ul><li>CalculateDecimal: The calculateDecimal function serves to adjust the token amount for the token’s decimal precision.</li></ul><pre>function calculateDecimal(uint256 _amount) internal view returns (uint256) {<br>        return _amount * 10**decimal;<br>    }</pre><h4>Full code</h4><pre>// SPDX-License-Identifier: MIT<br>pragma solidity ^0.8.8;<br><br>contract Token {<br>    uint256 totalSupply;<br>    address immutable owner;<br>    string public constant name = &quot;Pyde Pyper&quot;;<br>    string public constant symbol = &quot;Pyde&quot;;<br>    uint8 immutable decimal;<br>    event Approve(address indexed by, address indexed to, uint256 value);<br>    event Transfer(address indexed from, address indexed to, uint256 value);<br>    mapping(address =&gt; uint256) balance;<br>    mapping(address =&gt; mapping(address =&gt; uint256)) allowance;<br><br>    constructor() {<br>        decimal = 12;<br>        totalSupply = calculateDecimal(10_000_000_000);<br>        owner = msg.sender;<br>        balance[msg.sender] = totalSupply;<br>    }<br><br>    function transfer(address _recipient, uint256 _amount) external {<br>        require(_amount &gt; 0, &quot;Zero values are not allowed&quot;);<br>        uint256 charge = calculatePercentageCharge(calculateDecimal(_amount));<br>        require(<br>            totalSupply &gt;= calculateDecimal(_amount) + charge,<br>            &quot;Insufficient balance&quot;<br>        );<br>        if(msg.sender == owner){<br>            totalSupply -= (calculateDecimal(_amount)+charge);<br>        }<br>        uint256 _userAvailableBalance = balance[_recipient];<br>        balance[_recipient] = _userAvailableBalance + calculateDecimal(_amount);<br>        balance[msg.sender] =<br>            balance[msg.sender] -<br>            calculateDecimal(_amount) -<br>            charge;<br>    }<br><br>    function transferFrom(<br>        address _from,<br>        address _receiver,<br>        uint256 _amount<br>    ) external {<br>        require(_from != address(0), &quot;Invalid sender address&quot;);<br>        require(_receiver != address(0), &quot;Invalid recipient address&quot;);<br>        require(_amount &gt; 0, &quot;Zero values are not allowed&quot;);<br>        uint256 charge = calculatePercentageCharge(calculateDecimal(_amount));<br>        uint256 _total = calculateDecimal(_amount) + charge;<br>        require(balance[_from] &gt;= _total, &quot;Insufficient balance&quot;);<br>        require(allowance[_from][msg.sender] &gt;= _total, &quot;Allowance exceeded&quot;);<br>        balance[_from] -= _total;<br>        balance[_receiver] += calculateDecimal(_amount);<br>        allowance[_from][msg.sender] -= calculateDecimal(_amount);<br>        emit Transfer(msg.sender, _receiver, _amount);<br>    }<br><br>    function approve(address _user, uint256 _amount) external {<br>        require(msg.sender != address(0), &quot;Invalid address&quot;);<br>        require(_amount &gt; 0, &quot;Zero values are not allowed&quot;);<br>        require(<br>            _user != address(0),<br>            &quot;Transfers are not allowed to address zero&quot;<br>        );<br>        allowance[msg.sender][_user] = calculateDecimal(_amount);<br>        emit Approve(msg.sender, _user, _amount);<br>    }<br><br>    function burn(uint256 _amount) external {<br>        require(msg.sender == owner, &quot;Only owner has this privilege&quot;);<br>        require(totalSupply&gt;=calculateDecimal(_amount),&quot;Insufficient balance to burn&quot;);<br>        totalSupply -= calculateDecimal(_amount);<br>        balance[owner] -= calculateDecimal(_amount);<br>    }<br><br>    function calculatePercentageCharge(uint256 _amount)<br>        internal<br>        pure<br>        returns (uint256)<br>    {<br>        return (10 * _amount) / 100;<br>    }<br><br>    function calculateDecimal(uint256 _amount) internal view returns (uint256) {<br>        return _amount * 10**decimal;<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25b4c5fad4f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>