以下是一个简单的马蹄链智能合约系统的开发源码demo,它实现了一个简单的 Token 资产发行功能:
pragma solidity ^0.8.0;
contract Owned {
address public owner;
function Owned() {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner, "Only owner can call this function");
_;
}
}
contract Token {
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
uint256 public balanceOf;
mapping (address => uint256) balances;
constructor() {
name = "My Token";
symbol = "MTN";
decimals = 18;
totalSupply = 1000000;
}
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
function transfer(address _to, uint256 _value) public onlyOwner {
require(balances[owner] >= _value, "Insufficient funds");
balances[owner] -= _value;
balances[_to] += _value;
emit Transfer(owner, _to, _value);
}
}