// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract MintContract {
address public owner;
mapping(address => uint256) mintMainMap; //平台主币种认购数目
mapping(address => uint256) banlanceMap; //平台主币种余额数目
event BatchMintWithEther(
string indexed code,
uint256 indexed mainNum,
uint256 mainTotal,
uint256 currentNum
);
constructor() {
owner = msg.sender;
}
//使用modifile判断权限是不是某个人
modifier onlyOwner() {
require(owner == msg.sender, "only owner can call the function");
_;
}
//获取主币种余额
function getMainTokenBalance() public view returns (uint256) {
return address(msg.sender).balance;
}
function getContractAddressBalance() public view returns (uint256) {
return address(this).balance;
}
//获取合约的余额
function getContractOwnerBalance() public view onlyOwner returns(uint256) {
return address(owner).balance;
}
function getContractAddress() public view returns (address) {
return address(this); //0xd9145CCE52D386f254917e481eB44e9943F39138
}
// //向合约发送主币要在该函数添加payable关键字 a给b转账
function batchMintWithEther(string memory code,address receiveAddress, uint256 mintNum)
external
payable
{
require(msg.value > 0, "the balnace value must be more than 0");
uint256 amount = address(msg.sender).balance; //获取当前地址
require(amount > msg.value, "your wallet balance not enough");
//a给b转账 基于合约转平台币种
address payable receiveAdd = payable(receiveAddress); //拿到拉起钱包的人
//https://www.cnblogs.com/x-poior/p/10511583.htmlv
receiveAdd.transfer(msg.value);
banlanceMap[receiveAddress] += msg.value;
mintMainMap[msg.sender] += mintNum;
//可以转账
emit BatchMintWithEther(
code,
mintNum,
mintMainMap[msg.sender],
msg.value
);
}
}
2023-12-28 solidity 平台币种转账
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...