Skip to content

Instantly share code, notes, and snippets.

View ilamanov's full-sized avatar

Nazar Ilamanov ilamanov

View GitHub Profile
pragma solidity ^0.5.0;
// Mapping from owner to list of owned token IDs
mapping(address => uint256[]) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
pragma solidity ^0.5.0;
function _mint(address to, uint256 tokenId) internal {
_tokenOwner[tokenId] = to;
_ownedTokensCount[to].increment();
}
function _burn(address owner, uint256 tokenId) internal {
_ownedTokensCount[owner].decrement();
pragma solidity ^0.5.0;
// Mapping from token ID to approved address
mapping (uint256 => address) private _tokenApprovals;
function approve(address to, uint256 tokenId) public {
address owner = ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(msg.sender == owner || isApprovedForAll(owner, msg.sender),
pragma solidity ^0.5.0;
function transferFrom(address from, address to, uint256 tokenId) public {
// ...
_ownedTokensCount[from].decrement();
_ownedTokensCount[to].increment();
_tokenOwner[tokenId] = to;
// ...
}
pragma solidity ^0.5.0;
// Mapping from token ID to owner
mapping (uint256 => address) private _tokenOwner;
// Mapping from owner to number of owned token
mapping (address => Counters.Counter) private _ownedTokensCount;
function balanceOf(address owner) public view returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
@ilamanov
ilamanov / ERC-721.sol
Last active April 10, 2022 20:13
ERC-721
pragma solidity ^0.4.20;
interface ERC721 {
function name() public view returns (string);
function symbol() public view returns (string);
function tokenURI(uint256 _tokenId) public view returns (string);
function totalSupply() public view returns (uint256);
function tokenByIndex(uint256 _index) public view returns (uint256);
function tokenOfOwnerByIndex(address _owner, uint256 _index) public view returns (uint256);
@ilamanov
ilamanov / ArtBlocks.sol
Created March 24, 2022 15:28
The Art Blocks Solidity Smart Contract GitHub
/**
*Submitted for verification at Etherscan.io on 2020-12-12
*/
// File contracts/libs/IERC165.sol
// File: openzeppelin-solidity/contracts/introspection/IERC165.sol
pragma solidity ^0.5.0;
/**
/// @title A 6x6 chess engine with negamax search
/// @author fiveoutofnine
/// @notice Docstrings below are written from the perspective of black (i.e. written as if the
/// engine is always black). However, due to negamax's symmetric nature, the engine may be used for
/// white as well.
contract Engine {
using Chess for uint256;
using Engine for uint256;
/// @notice Searches for the ``best'' move.
@ilamanov
ilamanov / fiveoutofnineART.sol
Created March 19, 2022 12:30
art generation
/// @title A library that generates HTML art for fiveoutofnine (an on-chain 6x6 chess engine)
/// The art is generated as HTML code with in-line CSS (0 JS)
contract fiveoutofnineART {
/// @notice Takes in data for a given fiveoutofnine NFT and outputs its metadata in JSON form.
/// @param _internalId A bitpacked uint256 where the first 128 bits are the game ID, and the
/// last 128 bits are the move ID within the game.
/// @param _move A struct with information about the player's move and engine's response (see
/// {Chess-Move}).
/// @return Base 64-encoded JSON of metadata generated from `_internalId` and `_move`.
function getMetadata(uint256 _internalId, Chess.Move memory _move)
contract Example {
function playMove(uint256 _board) internal {
uint256 rotated = _board.rotate();
// ...
}
}