Search in sources :

Example 1 with TokenGrantKycTransaction

use of com.hedera.hashgraph.sdk.TokenGrantKycTransaction in project hedera-sdk-java by hashgraph.

the class TokenWipeIntegrationTest method canWipeAccountsBalance.

@Test
@DisplayName("Can wipe accounts balance")
void canWipeAccountsBalance() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var key = PrivateKey.generateED25519();
    var response = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(1)).execute(testEnv.client);
    var accountId = Objects.requireNonNull(response.getReceipt(testEnv.client).accountId);
    var tokenId = Objects.requireNonNull(new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setDecimals(3).setInitialSupply(1000000).setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).setFreezeKey(testEnv.operatorKey).setWipeKey(testEnv.operatorKey).setKycKey(testEnv.operatorKey).setSupplyKey(testEnv.operatorKey).setFreezeDefault(false).execute(testEnv.client).getReceipt(testEnv.client).tokenId);
    new TokenAssociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(tokenId)).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenGrantKycTransaction().setAccountId(accountId).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    new TransferTransaction().addTokenTransfer(tokenId, testEnv.operatorId, -10).addTokenTransfer(tokenId, accountId, 10).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenWipeTransaction().setTokenId(tokenId).setAccountId(accountId).setAmount(10).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) TokenWipeTransaction(com.hedera.hashgraph.sdk.TokenWipeTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with TokenGrantKycTransaction

use of com.hedera.hashgraph.sdk.TokenGrantKycTransaction in project hedera-sdk-java by hashgraph.

the class TokenWipeIntegrationTest method cannotWipeAccountsBalanceWhenAccountIDIsNotSet.

@Test
@DisplayName("Cannot wipe accounts balance when account ID is not set")
void cannotWipeAccountsBalanceWhenAccountIDIsNotSet() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var key = PrivateKey.generateED25519();
    var response = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(1)).execute(testEnv.client);
    var accountId = Objects.requireNonNull(response.getReceipt(testEnv.client).accountId);
    var tokenId = Objects.requireNonNull(new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setDecimals(3).setInitialSupply(1000000).setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).setFreezeKey(testEnv.operatorKey).setWipeKey(testEnv.operatorKey).setKycKey(testEnv.operatorKey).setSupplyKey(testEnv.operatorKey).setFreezeDefault(false).execute(testEnv.client).getReceipt(testEnv.client).tokenId);
    new TokenAssociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(tokenId)).freezeWith(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenGrantKycTransaction().setAccountId(accountId).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    new TransferTransaction().addTokenTransfer(tokenId, testEnv.operatorId, -10).addTokenTransfer(tokenId, accountId, 10).execute(testEnv.client).getReceipt(testEnv.client);
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        new TokenWipeTransaction().setTokenId(tokenId).setAmount(10).execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.INVALID_ACCOUNT_ID.toString());
    testEnv.close(tokenId, accountId, key);
}
Also used : TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) TokenWipeTransaction(com.hedera.hashgraph.sdk.TokenWipeTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with TokenGrantKycTransaction

use of com.hedera.hashgraph.sdk.TokenGrantKycTransaction in project hedera-sdk-java by hashgraph.

the class TokenNftTransferIntegrationTest method canTransferNfts.

@Test
@DisplayName("Can transfer NFTs")
void canTransferNfts() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var key = PrivateKey.generateED25519();
    @Var TransactionResponse response = new AccountCreateTransaction().setKey(key).setInitialBalance(new Hbar(1)).execute(testEnv.client);
    var accountId = response.getReceipt(testEnv.client).accountId;
    assertThat(accountId).isNotNull();
    response = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTokenType(TokenType.NON_FUNGIBLE_UNIQUE).setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).setFreezeKey(testEnv.operatorKey).setWipeKey(testEnv.operatorKey).setKycKey(testEnv.operatorKey).setSupplyKey(testEnv.operatorKey).setFreezeDefault(false).execute(testEnv.client);
    var tokenId = response.getReceipt(testEnv.client).tokenId;
    assertThat(tokenId).isNotNull();
    var mintReceipt = new TokenMintTransaction().setTokenId(tokenId).setMetadata(NftMetadataGenerator.generate((byte) 10)).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenAssociateTransaction().setAccountId(accountId).setTokenIds(Collections.singletonList(tokenId)).freezeWith(testEnv.client).signWithOperator(testEnv.client).sign(key).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenGrantKycTransaction().setAccountId(accountId).setTokenId(tokenId).execute(testEnv.client).getReceipt(testEnv.client);
    var serialsToTransfer = new ArrayList<Long>(mintReceipt.serials.subList(0, 4));
    var transfer = new TransferTransaction();
    for (var serial : serialsToTransfer) {
        transfer.addNftTransfer(tokenId.nft(serial), testEnv.operatorId, accountId);
    }
    transfer.execute(testEnv.client).getReceipt(testEnv.client);
    new TokenWipeTransaction().setTokenId(tokenId).setAccountId(accountId).setSerials(serialsToTransfer).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close(tokenId, accountId, key);
}
Also used : Var(com.google.errorprone.annotations.Var) TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) ArrayList(java.util.ArrayList) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) TransactionResponse(com.hedera.hashgraph.sdk.TransactionResponse) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) TokenWipeTransaction(com.hedera.hashgraph.sdk.TokenWipeTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with TokenGrantKycTransaction

use of com.hedera.hashgraph.sdk.TokenGrantKycTransaction in project hedera-sdk-java by hashgraph.

the class TransferTokensExample method main.

public static void main(String[] args) throws Exception {
    Client client = Client.forName(HEDERA_NETWORK);
    // Defaults the operator account ID and key such that all generated transactions will be paid for
    // by this account and be signed by this key
    client.setOperator(OPERATOR_ID, OPERATOR_KEY);
    // Generate a Ed25519 private, public key pair
    PrivateKey key1 = PrivateKey.generateED25519();
    PrivateKey key2 = PrivateKey.generateED25519();
    System.out.println("private key = " + key1);
    System.out.println("public key = " + key1.getPublicKey());
    System.out.println("private key = " + key2);
    System.out.println("public key = " + key2.getPublicKey());
    @Var TransactionResponse response = new AccountCreateTransaction().setKey(key1.getPublicKey()).setInitialBalance(Hbar.fromTinybars(1000)).execute(client);
    // This will wait for the receipt to become available
    @Var TransactionReceipt receipt = response.getReceipt(client);
    AccountId accountId1 = Objects.requireNonNull(receipt.accountId);
    System.out.println("accountId1 = " + accountId1);
    response = new AccountCreateTransaction().setKey(key2.getPublicKey()).setInitialBalance(Hbar.fromTinybars(1000)).execute(client);
    // This will wait for the receipt to become available
    receipt = response.getReceipt(client);
    AccountId accountId2 = Objects.requireNonNull(receipt.accountId);
    System.out.println("accountId2 = " + accountId1);
    response = new TokenCreateTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).setTokenName("ffff").setTokenSymbol("F").setDecimals(3).setInitialSupply(1000000).setTreasuryAccountId(OPERATOR_ID).setAdminKey(OPERATOR_KEY.getPublicKey()).setFreezeKey(OPERATOR_KEY.getPublicKey()).setWipeKey(OPERATOR_KEY.getPublicKey()).setKycKey(OPERATOR_KEY.getPublicKey()).setSupplyKey(OPERATOR_KEY.getPublicKey()).setFreezeDefault(false).execute(client);
    TokenId tokenId = Objects.requireNonNull(response.getReceipt(client).tokenId);
    System.out.println("token = " + tokenId);
    new TokenAssociateTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).setAccountId(accountId1).setTokenIds(Collections.singletonList(tokenId)).freezeWith(client).sign(OPERATOR_KEY).sign(key1).execute(client).getReceipt(client);
    System.out.println("Associated account " + accountId1 + " with token " + tokenId);
    new TokenAssociateTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).setAccountId(accountId2).setTokenIds(Collections.singletonList(tokenId)).freezeWith(client).sign(OPERATOR_KEY).sign(key2).execute(client).getReceipt(client);
    System.out.println("Associated account " + accountId2 + " with token " + tokenId);
    new TokenGrantKycTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).setAccountId(accountId1).setTokenId(tokenId).execute(client).getReceipt(client);
    System.out.println("Granted KYC for account " + accountId1 + " on token " + tokenId);
    new TokenGrantKycTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).setAccountId(accountId2).setTokenId(tokenId).execute(client).getReceipt(client);
    System.out.println("Granted KYC for account " + accountId2 + " on token " + tokenId);
    new TransferTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).addTokenTransfer(tokenId, OPERATOR_ID, -10).addTokenTransfer(tokenId, accountId1, 10).execute(client).getReceipt(client);
    System.out.println("Sent 10 tokens from account " + OPERATOR_ID + " to account " + accountId1 + " on token " + tokenId);
    new TransferTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).addTokenTransfer(tokenId, accountId1, -10).addTokenTransfer(tokenId, accountId2, 10).freezeWith(client).sign(key1).execute(client).getReceipt(client);
    System.out.println("Sent 10 tokens from account " + accountId1 + " to account " + accountId2 + " on token " + tokenId);
    new TransferTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).addTokenTransfer(tokenId, accountId2, -10).addTokenTransfer(tokenId, accountId1, 10).freezeWith(client).sign(key2).execute(client).getReceipt(client);
    System.out.println("Sent 10 tokens from account " + accountId2 + " to account " + accountId1 + " on token " + tokenId);
    new TokenWipeTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).setTokenId(tokenId).setAccountId(accountId1).setAmount(10).execute(client).getReceipt(client);
    System.out.println("Wiped balance of account " + accountId1);
    new TokenDeleteTransaction().setNodeAccountIds(Collections.singletonList(response.nodeId)).setTokenId(tokenId).execute(client).getReceipt(client);
    System.out.println("Deleted token " + tokenId);
    new AccountDeleteTransaction().setAccountId(accountId1).setTransferAccountId(OPERATOR_ID).freezeWith(client).sign(OPERATOR_KEY).sign(key1).execute(client).getReceipt(client);
    System.out.println("Deleted accountId1 " + accountId1);
    new AccountDeleteTransaction().setAccountId(accountId2).setTransferAccountId(OPERATOR_ID).freezeWith(client).sign(OPERATOR_KEY).sign(key2).execute(client).getReceipt(client);
    System.out.println("Deleted accountId2" + accountId2);
}
Also used : PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) AccountId(com.hedera.hashgraph.sdk.AccountId) Var(com.google.errorprone.annotations.Var) TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) TokenDeleteTransaction(com.hedera.hashgraph.sdk.TokenDeleteTransaction) AccountDeleteTransaction(com.hedera.hashgraph.sdk.AccountDeleteTransaction) TransactionReceipt(com.hedera.hashgraph.sdk.TransactionReceipt) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction) TransactionResponse(com.hedera.hashgraph.sdk.TransactionResponse) Client(com.hedera.hashgraph.sdk.Client) TokenId(com.hedera.hashgraph.sdk.TokenId) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) TokenWipeTransaction(com.hedera.hashgraph.sdk.TokenWipeTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction)

Example 5 with TokenGrantKycTransaction

use of com.hedera.hashgraph.sdk.TokenGrantKycTransaction in project hedera-mirror-node by hashgraph.

the class TokenClient method grantKyc.

public NetworkTransactionResponse grantKyc(TokenId tokenId, AccountId accountId) {
    log.debug("Grant account {} with KYC for token {}", accountId, tokenId);
    TokenGrantKycTransaction tokenGrantKycTransaction = new TokenGrantKycTransaction().setAccountId(accountId).setTokenId(tokenId).setMaxTransactionFee(sdkClient.getMaxTransactionFee()).setTransactionMemo(getMemo("Grant kyc for token"));
    NetworkTransactionResponse networkTransactionResponse = executeTransactionAndRetrieveReceipt(tokenGrantKycTransaction);
    log.debug("Granted Kyc for account {} with token {}", accountId, tokenId);
    return networkTransactionResponse;
}
Also used : NetworkTransactionResponse(com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse) TokenGrantKycTransaction(com.hedera.hashgraph.sdk.TokenGrantKycTransaction)

Aggregations

TokenGrantKycTransaction (com.hedera.hashgraph.sdk.TokenGrantKycTransaction)15 Test (org.junit.jupiter.api.Test)13 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)12 Hbar (com.hedera.hashgraph.sdk.Hbar)11 TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)11 DisplayName (org.junit.jupiter.api.DisplayName)11 TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)10 TokenWipeTransaction (com.hedera.hashgraph.sdk.TokenWipeTransaction)8 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)8 Var (com.google.errorprone.annotations.Var)3 TokenMintTransaction (com.hedera.hashgraph.sdk.TokenMintTransaction)3 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)3 AbstractTransactionSupplierTest (com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)2 AccountDeleteTransaction (com.hedera.hashgraph.sdk.AccountDeleteTransaction)1 AccountId (com.hedera.hashgraph.sdk.AccountId)1 Client (com.hedera.hashgraph.sdk.Client)1 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)1 TokenDeleteTransaction (com.hedera.hashgraph.sdk.TokenDeleteTransaction)1 TokenId (com.hedera.hashgraph.sdk.TokenId)1 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)1