forked from cisc0f/hedera
-
Notifications
You must be signed in to change notification settings - Fork 5
/
TokenSender.sol
47 lines (36 loc) · 1.47 KB
/
TokenSender.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
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.6.0 <0.9.0;
import './HederaResponseCodes.sol';
import './IHederaTokenService.sol';
import './HederaTokenService.sol';
import './ExpiryHelper.sol';
contract TokenSender is ExpiryHelper{
// Create fungible token, this contract as treasury
function createFungible(
string memory name,
string memory symbol,
uint initialSupply,
uint decimals,
uint32 autoRenewPeriod
) external payable returns (address createdTokenAddress) {
IHederaTokenService.HederaToken memory token;
token.name = name;
token.symbol = symbol;
token.treasury = address(this);
// create the expiry schedule for the token using ExpiryHelper
token.expiry = createAutoRenewExpiry(address(this), autoRenewPeriod);
// call HTS precompiled contract, passing initial supply and decimals
(int responseCode, address tokenAddress) =
HederaTokenService.createFungibleToken(token, initialSupply, decimals);
if (responseCode != HederaResponseCodes.SUCCESS) {
revert ();
}
createdTokenAddress = tokenAddress;
}
function tokenTransfer(address tokenId, address receiver, int64 amount) external {
int response = HederaTokenService.transferToken(tokenId, address(this), receiver, amount);
if (response != HederaResponseCodes.SUCCESS) {
revert ("Transfer Failed");
}
}
}