-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1_transferHbar2Contract_viaPayableFcn.sol
53 lines (38 loc) · 1.62 KB
/
1_transferHbar2Contract_viaPayableFcn.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.11;
pragma experimental ABIEncoderV2;
import "./hip-206/HederaTokenService.sol";
import "./hip-206/HederaResponseCodes.sol";
contract hbar2Contract is HederaTokenService {
address tokenAddress;
constructor(address _tokenAddress) public {
tokenAddress = _tokenAddress;
}
function mintFungibleToken(uint64 _amount) external {
(int response, uint64 newTotalSupply, int64[] memory serialNumbers) = HederaTokenService.mintToken(tokenAddress, _amount, new bytes[](0));
if (response != HederaResponseCodes.SUCCESS) {
revert ("Mint Failed");
}
}
function tokenAssociate(address _account) external {
int response = HederaTokenService.associateToken(_account, tokenAddress);
if (response != HederaResponseCodes.SUCCESS) {
revert ("Associate Failed");
}
}
function tokenTransfer(address _sender, address _receiver, int64 _amount) payable external {
// REQUIRE HBAR PAYMENT FOR FUNCTION EXECUTION
// if (msg.value < 5000000000) {
// revert ("Transfer Failed - Send more HBAR");
// }
// OR
require(msg.value > 1233000000,"Send more HBAR");
int response = HederaTokenService.transferToken(tokenAddress, _sender, _receiver, _amount);
if (response != HederaResponseCodes.SUCCESS) {
revert ("Transfer Failed");
}
}
function getBalance() public view returns (uint) {
return address(this).balance;
}
}