All Products
Search
Document Center

Account Interface

Last Updated: May 24, 2019

Create accounts

createAccount

You can call this synchronous operation to create an account.

  • Function
  1. public MychainBase<ReplyTransactionReceipt> createAccount(CreateAccountRequest request)
  • Request parameters
Name Required Type Description
request true CreateAccountRequest The request to create an account.
  • Response fields
Response field Field type Description
result MychainBase< ReplyTransactionReceipt> MychainBaseResult contains a response type.
  • Examples
  1. MychainBase<ReplyTransactionReceipt> result = sdk.getAccountService().createAccount(
  2. CreateAccountRequest.build(
  3. adminAccount.getIdentity(), testAccount1, params
  4. )
  5. );

asyncCreateAccount

You can call this asynchronous operation to create an account.

  • Function
  1. public MychainBase<Response> asyncCreateAccount(CreateAccountRequest request, ICallback callback)
  • Request parameters
Name Required Type Description
request true CreateAccountRequest The request to create an account.
callback true ICallback The callback function.
  • Response fields
Response field Field type Description
result MychainBaseResult MychainBaseResult contains a response type.
  • Examples
  1. MychainBase<Response> result = sdk.getAccountService().asyncCreateAccount(
  2. CreateAccountRequest.build(adminAccount.getIdentity(), testAccount3, params),
  3. new ICallback() {
  4. @Override
  5. public void onResponse(String txHash, Response response) {
  6. System.out.println("async create account, txHash:" + txHash + ", result: " + response.getErrorCode());
  7. }
  8. });

CreateAccountRequest

Parameters required to create an account:

Name Type Description
account Account The account to be created.
fromAccountId Identity The account ID of the creator.
mychainParams MychainParams Common expansion parameters

Transfers

transferBalance

You can call this synchronous operation to perform a transfer.

  • Function
  1. public MychainBase<ReplyTransactionReceipt> transferBalance(TransferBalanceRequest request)
  • Request parameters
Name Required Type Description
request true TransferBalanceRequest The transfer request.
  • Response fields
Response field Field type Description
result MychainBaseResult MychainBaseResult contains a response type.
  • Examples
  1. // build params
  2. MychainParams params = new MychainParams.Builder()
  3. .gas(BigInteger.valueOf(40000))
  4. .privateKeyList(adminPrivateKeys)
  5. .build();
  6. //transfer balance
  7. MychainBase<ReplyTransactionReceipt> result = sdk.getAccountService().transferBalance(
  8. TransferBalanceRequest.build(testAccount1.getIdentity(),
  9. testAccount2.getIdentity(),
  10. new BigInteger(transferAmount+""),
  11. params
  12. )
  13. );

asyncTransferBalance

You can call this asynchronous operation to perform a transfer.

  • Function
  1. public MychainBase<Response> asyncTransferBalance(TransferBalanceRequest request, ICallback callback)
  • Request parameters
Name Required Type Description
request true TransferBalanceRequest The transfer request.
callback true ICallback The callback function.
  • Response fields
Response field Field type Description
result MychainBaseResult MychainBaseResult contains a response type.
  • Examples
  1. // build params
  2. MychainParams params = new MychainParams.Builder()
  3. .gas(BigInteger.valueOf(40000))
  4. .privateKeyList(adminPrivateKeys)
  5. .build();
  6. // async transfer balance
  7. MychainBase<Response> result = sdk.getAccountService().asyncTransferBalance(
  8. TransferBalanceRequest.build(testAccount2.getIdentity(),
  9. testAccount1.getIdentity(),
  10. new BigInteger(transferAmount+""),
  11. params),
  12. (txHash, response) -> {
  13. System.out.println("async transfer balance, txHash:"+txHash+", result: "+ response.getErrorCode());
  14. }
  15. );

TransferBalanceRequest

Parameters required to perform a transfer.

Name Type Description
fromAcctId Identity The account from which the money is transferred.
toAcctId Identity The account to which the money is transferred.
amount BigInteger The transferred amount.
mychainParams MychainParams Common parameters

Set recovery keys

setRecoverKey

You can call this synchronous operation to set the recovery key.

  • Function
  1. public MychainBase<ReplyTransactionReceipt> setRecoverKey(SetRecoverKeyRequest request)
  • Request parameters
Name Required Type Description
request true SetRecoverKeyRequest The request to set a recovery public key.
  • Response fields
Response field Field type Description
result MychainBaseResult MychainBaseResult contains a response type.
  • Examples
  1. // build params
  2. MychainParams params = new MychainParams.Builder()
  3. .gas(BigInteger.valueOf(40000))
  4. .privateKeyList(adminPrivateKeys)
  5. .build();
  6. MychainBase<ReplyTransactionReceipt> result = sdk.getAccountService().setRecoverKey(
  7. SetRecoverKeyRequest.build(testAccount1.getIdentity(), newRecoverKey, params));

asyncSetRecoverKey

You can call this asynchronous operation to set the recovery public key.

  • Function
  1. public MychainBase<Response> asyncSetRecoverKey(SetRecoverKeyRequest request, ICallback callback)
  • Request parameters
Name Required Type Description
request true SetRecoverKeyRequest The request to set a recovery public key.
callback true ICallback The callback function.
  • Response fields
Response field Field type Description
result MychainBase MychainBaseResult contains a response type.
  • Examples
  1. // build params
  2. MychainParams params = new MychainParams.Builder()
  3. .gas(BigInteger.valueOf(40000))
  4. .privateKeyList(adminPrivateKeys)
  5. .build();
  6. MychainBase<Response> result = sdk.getAccountService().asyncSetRecoverKey(
  7. SetRecoverKeyRequest.build(testAccount1.getIdentity(), newRecoverKey, params),
  8. new ICallback() {
  9. @Override
  10. public void onResponse(String txHash, Response response) {
  11. System.out.println("async set recover key, txHash:" + txHash + ", result: "
  12. + response.getErrorCode());
  13. }
  14. });

SetRecoverKeyRequest

Parameters that are required to reset the recovery public key:

Name Type Description
acctId Identity The account ID to be set.
recoverPubKey String The new recovery public key.
mychainParams MychainParams Common parameters

Pre-reset public keys

preResetPubKey

You can call this synchronous operation to pre-reset the public key.

  • Function
  1. public MychainBase<ReplyTransactionReceipt> preResetPubKey(PreResetPubKeyRequest request)
  • Request parameters
Name Required Type Description
request true PreResetPubKeyRequest The request to pre-reset the public key.
  • Response fields
Response field Field type Description
result MychainBase MychainBaseResult contains a response type.
  • Examples
  1. // build params
  2. MychainParams params = new MychainParams.Builder()
  3. .gas(BigInteger.valueOf(40000))
  4. .privateKeyList(adminPrivateKeys)
  5. .build();
  6. // pre reset
  7. MychainBase<ReplyTransactionReceipt> result = sdk.getAccountService().preResetPubKey(PreResetPubKeyRequest.build( acctId, params));

asyncPreResetPubKey

You can call this asynchronous operation to pre-reset the public key.

  • Function
  1. public MychainBase<Response> asyncPreResetPubKey(PreResetPubKeyRequest request, ICallback callback)
  • Request parameters
Name Required Type Description
request true PreResetPubKeyRequest The requests to pre-reset the public key.
callback true ICallback The callback function.
  • Response fields
Response field Field type Description
result MychainBase MychainBaseResult contains a response type.
  • Examples
  1. // build params
  2. MychainParams params = new MychainParams.Builder()
  3. .gas(BigInteger.valueOf(40000))
  4. .privateKeyList(adminPrivateKeys)
  5. .build();
  6. MychainBase<Response> response = sdk.getAccountService().asyncPreResetPubKey(
  7. PreResetPubKeyRequest.build(accId, params), new ICallback() {
  8. @Override
  9. public void onResponse(String txHash, Response response) {
  10. }
  11. });

PreResetPubKeyRequest

Parameters required to pre-reset the public key.

Name Type Description
acctId Identity The account ID to be preset.
mychainParams MychainParams Common parameters

Reset public keys

resetPubKey

You can call this synchronous operation to reset the public key.

  • Function
  1. public MychainBase<ReplyTransactionReceipt> resetPubKey(ResetPubKeyRequest request)
  • Request parameters
Name Required Type Description
request true ResetPubKeyTransaction The request to reset the public key.
  • Response fields
Response field Field type Description
result MychainBase MychainBaseResult contains a response type.
  • Examples
  1. // build params
  2. MychainParams params = new MychainParams.Builder()
  3. .gas(BigInteger.valueOf(40000))
  4. .privateKeyList(adminPrivateKeys)
  5. .build();
  6. // reset public key
  7. MychainBase<Response> response = sdk.getAccountService().resetPubKey(
  8. ResetPubKeyRequest.build(testAccount1.getIdentity(), authMap, params));

asyncResetPubKey

You can call this asynchronous operation to reset the public key.

  • Function
  1. public MychainBase<Response> asyncResetPubKey(ResetPubKeyRequest request,ICallback callback)
  • Request parameters
Name Required Type Description
request true ResetPubKeyRequest The request to reset the public key.
callback true ICallback The callback function.
  • Response fields
Response field Field type Description
result MychainBase MychainBaseResult contains a response type.
  • Examples
  1. // build params
  2. MychainParams params = new MychainParams.Builder()
  3. .gas(BigInteger.valueOf(40000))
  4. .privateKeyList(adminPrivateKeys)
  5. .build();
  6. // reset public key
  7. MychainBase<Response> response = sdk.getAccountService().asyncResetPubKey(
  8. ResetPubKeyRequest.build(testAccount1.getIdentity(), beforeAuthMap, params),
  9. new ICallback() {
  10. @Override
  11. public void onResponse(String txHash, Response response) {
  12. System.out.println("async reset pubkey, txHash:" + txHash + ", result: " + response.getErrorCode());
  13. }
  14. });

ResetPubKeyRequest

Parameters required to reset the public key.

Name Type Description
acctId Identity The account ID to be reset.
mychainParams MychainParams Common parameters

Update weights

updateAuthMap

You can call this synchronous operation to update the weights.

  • Function
  1. public MychainBase<ReplyTransactionReceipt> updateAuthMap(UpdateAuthMapRequest request)
  • Request parameters
Name Required Type Description
request true UpdateAuthMapRequest The request to update the weights.
  • Response fields
Response field Field type Description
result MychainBase MychainBaseResult contains a response type.
  • Examples
  1. // build params
  2. MychainParams params = new MychainParams.Builder()
  3. .gas(BigInteger.valueOf(40000))
  4. .privateKeyList(adminPrivateKeys)
  5. .build();
  6. // update authmap
  7. MychainBase<ReplyTransactionReceipt> response = sdk.getAccountService().updateAuthMap(
  8. UpdateAuthMapRequest.build(testAccount1.getIdentity(), beforeAuthMap, params));

asyncUpdateAuthMap

You can call this asynchronous operation to update the weights.

  • Function
  1. public MychainBase<Response> asyncUpdateAuthMap(UpdateAuthMapRequest request,ICallback callback)
  • Request parameters
Name Required Type Description
request true UpdateAuthMapRequest The request to reset the public key.
callback true ICallback The callback function.
  • Response fields
Response field Field type Description
result MychainBase MychainBaseResult contains a response type.
  • Examples
  1. // build params
  2. MychainParams params = new MychainParams.Builder()
  3. .gas(BigInteger.valueOf(40000))
  4. .privateKeyList(adminPrivateKeys)
  5. .build();
  6. AuthMap beforeAuthMap = sdk.getQueryService()
  7. .queryAccount(testAccount1.getIdentity().hexStrValue()).getData().getAccount().getAuthMap();
  8. for (Map.Entry<String, Integer> entry : beforeAuthMap.getAuthMap().entrySet()) {
  9. beforeAuthMap.updateAuth(entry.getKey(), entry.getValue() + 10);
  10. }
  11. MychainBase<Response> result = sdk.getAccountService().asyncUpdateAuthMap(
  12. UpdateAuthMapRequest.build(testAccount1.getIdentity(), beforeAuthMap, params),
  13. new ICallback() {
  14. @Override
  15. public void onResponse(String txHash, Response response) {
  16. System.out.println("async update auth map, txHash:" + txHash + ", result: " + response.getErrorCode());
  17. }
  18. });

UpdateAuthMapRequest

Parameters required to update the weights:

Name Type Description
acctId Identity The account ID to be configured.
authMap AuthMap The new weight.
mychainParams MychainParams Common parameters

Freeze accounts

freezeAccount

You can call this synchronous operation to freeze an account.

  • Function
  1. public MychainBase<ReplyTransactionReceipt> freezeAccount(FreezeAccountRequest request)
  • Request parameters
Name Required Type Description
request true FreezeAccountRequest The request to freeze an account.
  • Response fields
Response field Field type Description
result MychainBase MychainBaseResult contains a response type.
  • Examples
  1. // build params
  2. MychainParams params = new MychainParams.Builder()
  3. .gas(BigInteger.valueOf(40000))
  4. .privateKeyList(adminPrivateKeys)
  5. .build();
  6. // freeze account
  7. MychainBase<ReplyTransactionReceipt> result = sdk.getAccountService().freezeAccount(
  8. FreezeAccountRequest.build(adminAccount.getIdentity(), testAccount1.getIdentity(),
  9. params))

asyncFreezeAccount

You can call this asynchronous operation to freeze an account.

  • Function
  1. public MychainBase<Response> asyncFreezeAccount(FreezeAccountRequest request,ICallback callback)
  • Request parameters
Name Required Type Description
request true FreezeAccountRequest The request to freeze an account.
callback true ICallback The callback function.
  • Response fields
Response field Field type Description
result MychainBase MychainBaseResult contains a response type.
  • Examples
  1. // build params
  2. MychainParams params = new MychainParams.Builder()
  3. .gas(BigInteger.valueOf(40000))
  4. .privateKeyList(adminPrivateKeys)
  5. .build();
  6. // async freeze account
  7. MychainBase<Response> result = sdk.getAccountService().asyncFreezeAccount(
  8. FreezeAccountRequest.build(adminAccount.getIdentity(), testAccount1.getIdentity(),
  9. params), new ICallback() {
  10. @Override
  11. public void onResponse(String txHash, Response response) {
  12. assertNotNull(txHash);
  13. assertTrue(response.getErrorCode().isSuccess());
  14. }
  15. });

FreezeAccountRequest

Parameters required by the request to freeze an account:

Name Type Description
from Identity The ID of the user who freezes the account.
to Identity The account ID to be frozen.
mychainParams MychainParams Common parameters

Unfreeze accounts

unFreezeAccount

You can call this synchronous operation to unfreeze an account.

  • Function
  1. public MychainBase<ReplyTransactionReceipt> unFreezeAccount(UnfreezeAccountRequest request)
  • Request parameters
Name Required Type Description
request true UnfreezeAccountRequest The request to unfreeze an account.
  • Response fields
Response field Field type Description
result MychainBase<ReplyTransactionReceipt> MychainBaseResult contains a response type.
  • Examples
  1. // build params
  2. MychainParams params = new MychainParams.Builder()
  3. .gas(BigInteger.valueOf(40000))
  4. .privateKeyList(adminPrivateKeys)
  5. .build();
  6. // unfreeze account
  7. MychainBase<ReplyTransactionReceipt> result2 = sdk.getAccountService()
  8. .unFreezeAccount(
  9. UnfreezeAccountRequest.build(adminAccount.getIdentity(),
  10. testAccount1.getIdentity(), params));

asyncUnFreezeAccount

You can call this asynchronous operation to unfreeze an account.

  • Function
  1. public MychainBase<Response> asyncUnFreezeAccount(UnfreezeAccountRequest request,ICallback callback)
  • Request parameters
Name Required Type Description
request true UnfreezeAccountRequest The request to unfreeze an account.
callback true ICallback The callback function.
  • Response fields
Response field Field type Description
result MychainBase MychainBaseResult contains a response type.
  • Examples
  1. // build params
  2. MychainParams params = new MychainParams.Builder()
  3. .gas(BigInteger.valueOf(40000))
  4. .privateKeyList(adminPrivateKeys)
  5. .build();
  6. // async unfreeze account
  7. MychainBase<Response> result2 = sdk.getAccountService().asyncUnFreezeAccount(
  8. UnfreezeAccountRequest.build(adminAccount.getIdentity(), testAccount1.getIdentity(),
  9. params), new ICallback() {
  10. @Override
  11. public void onResponse(String txHash, Response response) {
  12. assertNotNull(txHash);
  13. assertTrue(response.getErrorCode().isSuccess());
  14. }
  15. });

UnfreezeAccountRequest

Parameters required by the request to to unfreeze an account:

Name Type Description
from Identity The account ID of the user who unfreezes the account.
to Identity The ID of the account to be unfrozen.
mychainParams MychainParams Common parameters