Skip to main content
Glama

Rootstock MCP Server

by cuongpo
erc20-contracts.ts18.6 kB
/** * ERC20 and ERC721 Contract Templates and ABIs for Hyperion MCP Server */ // Standard ERC20 ABI export const ERC20_ABI = [ // Read functions "function name() view returns (string)", "function symbol() view returns (string)", "function decimals() view returns (uint8)", "function totalSupply() view returns (uint256)", "function balanceOf(address owner) view returns (uint256)", "function allowance(address owner, address spender) view returns (uint256)", // Write functions "function transfer(address to, uint256 amount) returns (bool)", "function approve(address spender, uint256 amount) returns (bool)", "function transferFrom(address from, address to, uint256 amount) returns (bool)", // Events "event Transfer(address indexed from, address indexed to, uint256 value)", "event Approval(address indexed owner, address indexed spender, uint256 value)" ]; // Mintable ERC20 ABI (extends standard ERC20) export const MINTABLE_ERC20_ABI = [ ...ERC20_ABI, "function mint(address to, uint256 amount) returns (bool)", "function owner() view returns (address)", "function renounceOwnership()", "function transferOwnership(address newOwner)", "event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)" ]; // Burnable ERC20 ABI (extends standard ERC20) export const BURNABLE_ERC20_ABI = [ ...ERC20_ABI, "function burn(uint256 amount)", "function burnFrom(address account, uint256 amount)" ]; // Full featured ERC20 ABI (mintable + burnable) export const FULL_ERC20_ABI = [ ...ERC20_ABI, "function mint(address to, uint256 amount) returns (bool)", "function burn(uint256 amount)", "function burnFrom(address account, uint256 amount)", "function owner() view returns (address)", "function renounceOwnership()", "function transferOwnership(address newOwner)", "event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)" ]; // Standard ERC20 Solidity source code export const STANDARD_ERC20_SOURCE = ` // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract StandardERC20 { string public name; string public symbol; uint8 public decimals; uint256 public totalSupply; mapping(address => uint256) public balanceOf; mapping(address => mapping(address => uint256)) public allowance; event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _initialSupply) { name = _name; symbol = _symbol; decimals = _decimals; totalSupply = _initialSupply * 10**_decimals; balanceOf[msg.sender] = totalSupply; emit Transfer(address(0), msg.sender, totalSupply); } function transfer(address to, uint256 amount) public returns (bool) { require(balanceOf[msg.sender] >= amount, "Insufficient balance"); balanceOf[msg.sender] -= amount; balanceOf[to] += amount; emit Transfer(msg.sender, to, amount); return true; } function approve(address spender, uint256 amount) public returns (bool) { allowance[msg.sender][spender] = amount; emit Approval(msg.sender, spender, amount); return true; } function transferFrom(address from, address to, uint256 amount) public returns (bool) { require(balanceOf[from] >= amount, "Insufficient balance"); require(allowance[from][msg.sender] >= amount, "Insufficient allowance"); balanceOf[from] -= amount; balanceOf[to] += amount; allowance[from][msg.sender] -= amount; emit Transfer(from, to, amount); return true; } }`; // Mintable ERC20 Solidity source code export const MINTABLE_ERC20_SOURCE = ` // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract MintableERC20 { string public name; string public symbol; uint8 public decimals; uint256 public totalSupply; address public owner; mapping(address => uint256) public balanceOf; mapping(address => mapping(address => uint256)) public allowance; event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); modifier onlyOwner() { require(msg.sender == owner, "Not the owner"); _; } constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _initialSupply) { name = _name; symbol = _symbol; decimals = _decimals; totalSupply = _initialSupply * 10**_decimals; owner = msg.sender; balanceOf[msg.sender] = totalSupply; emit Transfer(address(0), msg.sender, totalSupply); emit OwnershipTransferred(address(0), msg.sender); } function transfer(address to, uint256 amount) public returns (bool) { require(balanceOf[msg.sender] >= amount, "Insufficient balance"); balanceOf[msg.sender] -= amount; balanceOf[to] += amount; emit Transfer(msg.sender, to, amount); return true; } function approve(address spender, uint256 amount) public returns (bool) { allowance[msg.sender][spender] = amount; emit Approval(msg.sender, spender, amount); return true; } function transferFrom(address from, address to, uint256 amount) public returns (bool) { require(balanceOf[from] >= amount, "Insufficient balance"); require(allowance[from][msg.sender] >= amount, "Insufficient allowance"); balanceOf[from] -= amount; balanceOf[to] += amount; allowance[from][msg.sender] -= amount; emit Transfer(from, to, amount); return true; } function mint(address to, uint256 amount) public onlyOwner returns (bool) { totalSupply += amount; balanceOf[to] += amount; emit Transfer(address(0), to, amount); return true; } function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0), "New owner is the zero address"); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } function renounceOwnership() public onlyOwner { emit OwnershipTransferred(owner, address(0)); owner = address(0); } }`; // Contract bytecode will be generated dynamically using ethers.js ContractFactory // This is a placeholder for the contract deployment interface export interface ContractTemplate { name: string; source: string; abi: string[]; constructorParams: string[]; } // Standard ERC721 ABI export const ERC721_ABI = [ // Read functions "function name() view returns (string)", "function symbol() view returns (string)", "function tokenURI(uint256 tokenId) view returns (string)", "function totalSupply() view returns (uint256)", "function balanceOf(address owner) view returns (uint256)", "function ownerOf(uint256 tokenId) view returns (address)", "function getApproved(uint256 tokenId) view returns (address)", "function isApprovedForAll(address owner, address operator) view returns (bool)", // Write functions "function approve(address to, uint256 tokenId)", "function setApprovalForAll(address operator, bool approved)", "function transferFrom(address from, address to, uint256 tokenId)", "function safeTransferFrom(address from, address to, uint256 tokenId)", "function safeTransferFrom(address from, address to, uint256 tokenId, bytes data)", // Events "event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)", "event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId)", "event ApprovalForAll(address indexed owner, address indexed operator, bool approved)" ]; // Mintable ERC721 ABI (extends standard ERC721) export const MINTABLE_ERC721_ABI = [ ...ERC721_ABI, "function mint(address to, uint256 tokenId, string uri) returns (bool)", "function safeMint(address to, uint256 tokenId, string uri) returns (bool)", "function owner() view returns (address)", "function renounceOwnership()", "function transferOwnership(address newOwner)", "event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)" ]; // Standard ERC721 Solidity source code export const STANDARD_ERC721_SOURCE = ` // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract StandardERC721 { string public name; string public symbol; uint256 public totalSupply; mapping(uint256 => address) public ownerOf; mapping(address => uint256) public balanceOf; mapping(uint256 => address) public getApproved; mapping(address => mapping(address => bool)) public isApprovedForAll; mapping(uint256 => string) public tokenURI; event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); event ApprovalForAll(address indexed owner, address indexed operator, bool approved); constructor(string memory _name, string memory _symbol) { name = _name; symbol = _symbol; } function approve(address to, uint256 tokenId) public { address owner = ownerOf[tokenId]; require(to != owner, "Approval to current owner"); require(msg.sender == owner || isApprovedForAll[owner][msg.sender], "Not owner nor approved"); getApproved[tokenId] = to; emit Approval(owner, to, tokenId); } function setApprovalForAll(address operator, bool approved) public { require(operator != msg.sender, "Approve to caller"); isApprovedForAll[msg.sender][operator] = approved; emit ApprovalForAll(msg.sender, operator, approved); } function transferFrom(address from, address to, uint256 tokenId) public { require(_isApprovedOrOwner(msg.sender, tokenId), "Not owner nor approved"); _transfer(from, to, tokenId); } function safeTransferFrom(address from, address to, uint256 tokenId) public { safeTransferFrom(from, to, tokenId, ""); } function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public { require(_isApprovedOrOwner(msg.sender, tokenId), "Not owner nor approved"); _safeTransfer(from, to, tokenId, data); } function _transfer(address from, address to, uint256 tokenId) internal { require(ownerOf[tokenId] == from, "Transfer from incorrect owner"); require(to != address(0), "Transfer to zero address"); // Clear approvals from the previous owner getApproved[tokenId] = address(0); balanceOf[from] -= 1; balanceOf[to] += 1; ownerOf[tokenId] = to; emit Transfer(from, to, tokenId); } function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, data), "Transfer to non ERC721Receiver"); } function _isApprovedOrOwner(address spender, uint256 tokenId) internal view returns (bool) { require(ownerOf[tokenId] != address(0), "Token does not exist"); address owner = ownerOf[tokenId]; return (spender == owner || getApproved[tokenId] == spender || isApprovedForAll[owner][spender]); } function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) private returns (bool) { if (to.code.length > 0) { try IERC721Receiver(to).onERC721Received(msg.sender, from, tokenId, data) returns (bytes4 retval) { return retval == IERC721Receiver.onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("Transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } } interface IERC721Receiver { function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4); }`; // Mintable ERC721 Solidity source code export const MINTABLE_ERC721_SOURCE = ` // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract MintableERC721 { string public name; string public symbol; uint256 public totalSupply; address public owner; mapping(uint256 => address) public ownerOf; mapping(address => uint256) public balanceOf; mapping(uint256 => address) public getApproved; mapping(address => mapping(address => bool)) public isApprovedForAll; mapping(uint256 => string) public tokenURI; event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); event ApprovalForAll(address indexed owner, address indexed operator, bool approved); event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); modifier onlyOwner() { require(msg.sender == owner, "Not the owner"); _; } constructor(string memory _name, string memory _symbol) { name = _name; symbol = _symbol; owner = msg.sender; emit OwnershipTransferred(address(0), msg.sender); } function mint(address to, uint256 tokenId, string memory uri) public onlyOwner returns (bool) { require(to != address(0), "Mint to zero address"); require(ownerOf[tokenId] == address(0), "Token already exists"); balanceOf[to] += 1; ownerOf[tokenId] = to; tokenURI[tokenId] = uri; totalSupply += 1; emit Transfer(address(0), to, tokenId); return true; } function safeMint(address to, uint256 tokenId, string memory uri) public onlyOwner returns (bool) { mint(to, tokenId, uri); require(_checkOnERC721Received(address(0), to, tokenId, ""), "Transfer to non ERC721Receiver"); return true; } function approve(address to, uint256 tokenId) public { address tokenOwner = ownerOf[tokenId]; require(to != tokenOwner, "Approval to current owner"); require(msg.sender == tokenOwner || isApprovedForAll[tokenOwner][msg.sender], "Not owner nor approved"); getApproved[tokenId] = to; emit Approval(tokenOwner, to, tokenId); } function setApprovalForAll(address operator, bool approved) public { require(operator != msg.sender, "Approve to caller"); isApprovedForAll[msg.sender][operator] = approved; emit ApprovalForAll(msg.sender, operator, approved); } function transferFrom(address from, address to, uint256 tokenId) public { require(_isApprovedOrOwner(msg.sender, tokenId), "Not owner nor approved"); _transfer(from, to, tokenId); } function safeTransferFrom(address from, address to, uint256 tokenId) public { safeTransferFrom(from, to, tokenId, ""); } function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public { require(_isApprovedOrOwner(msg.sender, tokenId), "Not owner nor approved"); _safeTransfer(from, to, tokenId, data); } function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0), "New owner is the zero address"); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } function renounceOwnership() public onlyOwner { emit OwnershipTransferred(owner, address(0)); owner = address(0); } function _transfer(address from, address to, uint256 tokenId) internal { require(ownerOf[tokenId] == from, "Transfer from incorrect owner"); require(to != address(0), "Transfer to zero address"); getApproved[tokenId] = address(0); balanceOf[from] -= 1; balanceOf[to] += 1; ownerOf[tokenId] = to; emit Transfer(from, to, tokenId); } function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, data), "Transfer to non ERC721Receiver"); } function _isApprovedOrOwner(address spender, uint256 tokenId) internal view returns (bool) { require(ownerOf[tokenId] != address(0), "Token does not exist"); address tokenOwner = ownerOf[tokenId]; return (spender == tokenOwner || getApproved[tokenId] == spender || isApprovedForAll[tokenOwner][spender]); } function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) private returns (bool) { if (to.code.length > 0) { try IERC721Receiver(to).onERC721Received(msg.sender, from, tokenId, data) returns (bytes4 retval) { return retval == IERC721Receiver.onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("Transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } } interface IERC721Receiver { function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4); }`; export const CONTRACT_TEMPLATES: Record<string, ContractTemplate> = { standard: { name: "StandardERC20", source: STANDARD_ERC20_SOURCE, abi: ERC20_ABI, constructorParams: ["string", "string", "uint8", "uint256"] }, mintable: { name: "MintableERC20", source: MINTABLE_ERC20_SOURCE, abi: MINTABLE_ERC20_ABI, constructorParams: ["string", "string", "uint8", "uint256"] }, erc721: { name: "StandardERC721", source: STANDARD_ERC721_SOURCE, abi: ERC721_ABI, constructorParams: ["string", "string"] }, mintableErc721: { name: "MintableERC721", source: MINTABLE_ERC721_SOURCE, abi: MINTABLE_ERC721_ABI, constructorParams: ["string", "string"] } };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cuongpo/rootstock-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server