The account service (sdk.getAccountService()) exposes methods to manage on-chain accounts in the Mychain network. Each method follows the same pattern: build a request object, call the method, and handle the response.
Synchronous methods block until the transaction is confirmed and return
MychainBase<ReplyTransactionReceipt>.Asynchronous methods return immediately and deliver the result to an
ICallbackcallback, returningMychainBase<Response>.
This reference covers the following operations:
All examples use the following common parameters block:
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();Create accounts
createAccount
Creates an account synchronously.
Signature
public MychainBase<ReplyTransactionReceipt> createAccount(CreateAccountRequest request)Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
request | Yes | CreateAccountRequest | The account creation request. |
Response
| Field | Type | Description |
|---|---|---|
result | MychainBase<ReplyTransactionReceipt> | Contains a response field with the transaction receipt. |
Example
MychainBase<ReplyTransactionReceipt> result = sdk.getAccountService().createAccount(
CreateAccountRequest.build(
adminAccount.getIdentity(), testAccount1, params
)
);asyncCreateAccount
Creates an account asynchronously. The result is delivered to the ICallback callback once the transaction is confirmed.
Signature
public MychainBase<Response> asyncCreateAccount(CreateAccountRequest request, ICallback callback)Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
request | Yes | CreateAccountRequest | The account creation request. |
callback | Yes | ICallback | The callback that receives the transaction hash and response. |
Response
| Field | Type | Description |
|---|---|---|
result | MychainBase<Response> | Contains a response field. |
Example
MychainBase<Response> result = sdk.getAccountService().asyncCreateAccount(
CreateAccountRequest.build(adminAccount.getIdentity(), testAccount3, params),
new ICallback() {
@Override
public void onResponse(String txHash, Response response) {
System.out.println("async create account, txHash:" + txHash + ", result: " + response.getErrorCode());
}
});CreateAccountRequest
| Field | Type | Description |
|---|---|---|
account | Account | The account to create. |
fromAccountId | Identity | The identity of the creator. The creator must have sufficient permissions. |
mychainParams | MychainParams | Common parameters, including gas limit and signing keys. |
Transfers
transferBalance
Transfers balance between accounts synchronously.
Signature
public MychainBase<ReplyTransactionReceipt> transferBalance(TransferBalanceRequest request)Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
request | Yes | TransferBalanceRequest | The transfer request. |
Response
| Field | Type | Description |
|---|---|---|
result | MychainBase<ReplyTransactionReceipt> | Contains a response field with the transaction receipt. |
Example
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
MychainBase<ReplyTransactionReceipt> result = sdk.getAccountService().transferBalance(
TransferBalanceRequest.build(
testAccount1.getIdentity(),
testAccount2.getIdentity(),
new BigInteger(transferAmount + ""),
params
)
);asyncTransferBalance
Transfers balance between accounts asynchronously.
Signature
public MychainBase<Response> asyncTransferBalance(TransferBalanceRequest request, ICallback callback)Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
request | Yes | TransferBalanceRequest | The transfer request. |
callback | Yes | ICallback | The callback that receives the transaction hash and response. |
Response
| Field | Type | Description |
|---|---|---|
result | MychainBase<Response> | Contains a response field. |
Example
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
MychainBase<Response> result = sdk.getAccountService().asyncTransferBalance(
TransferBalanceRequest.build(
testAccount2.getIdentity(),
testAccount1.getIdentity(),
new BigInteger(transferAmount + ""),
params),
(txHash, response) -> {
System.out.println("async transfer balance, txHash:" + txHash
+ ", result: " + response.getErrorCode());
}
);TransferBalanceRequest
| Field | Type | Description |
|---|---|---|
fromAcctId | Identity | The identity of the sending account. |
toAcctId | Identity | The identity of the receiving account. |
amount | BigInteger | The amount to transfer. |
mychainParams | MychainParams | Common parameters, including gas limit and signing keys. |
Set recovery keys
setRecoverKey
Sets the recovery public key for an account synchronously. The recovery key enables the two-step public key reset flow (preResetPubKey followed by resetPubKey).
Signature
public MychainBase<ReplyTransactionReceipt> setRecoverKey(SetRecoverKeyRequest request)Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
request | Yes | SetRecoverKeyRequest | The request to set a recovery public key. |
Response
| Field | Type | Description |
|---|---|---|
result | MychainBase<ReplyTransactionReceipt> | Contains a response field with the transaction receipt. |
Example
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
MychainBase<ReplyTransactionReceipt> result = sdk.getAccountService().setRecoverKey(
SetRecoverKeyRequest.build(testAccount1.getIdentity(), newRecoverKey, params));asyncSetRecoverKey
Sets the recovery public key for an account asynchronously.
Signature
public MychainBase<Response> asyncSetRecoverKey(SetRecoverKeyRequest request, ICallback callback)Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
request | Yes | SetRecoverKeyRequest | The request to set a recovery public key. |
callback | Yes | ICallback | The callback that receives the transaction hash and response. |
Response
| Field | Type | Description |
|---|---|---|
result | MychainBase<Response> | Contains a response field. |
Example
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
MychainBase<Response> result = sdk.getAccountService().asyncSetRecoverKey(
SetRecoverKeyRequest.build(testAccount1.getIdentity(), newRecoverKey, params),
new ICallback() {
@Override
public void onResponse(String txHash, Response response) {
System.out.println("async set recover key, txHash:" + txHash
+ ", result: " + response.getErrorCode());
}
});SetRecoverKeyRequest
| Field | Type | Description |
|---|---|---|
acctId | Identity | The identity of the account to update. |
recoverPubKey | String | The new recovery public key. |
mychainParams | MychainParams | Common parameters, including gas limit and signing keys. |
Pre-reset public keys
Resetting an account's public key requires two steps: call preResetPubKey first to initiate the rotation, then call resetPubKey to complete it.
preResetPubKey
Initiates the public key reset process synchronously.
Signature
public MychainBase<ReplyTransactionReceipt> preResetPubKey(PreResetPubKeyRequest request)Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
request | Yes | PreResetPubKeyRequest | The request to initiate the public key reset. |
Response
| Field | Type | Description |
|---|---|---|
result | MychainBase<ReplyTransactionReceipt> | Contains a response field with the transaction receipt. |
Example
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
MychainBase<ReplyTransactionReceipt> result = sdk.getAccountService().preResetPubKey(
PreResetPubKeyRequest.build(acctId, params));asyncPreResetPubKey
Initiates the public key reset process asynchronously.
Signature
public MychainBase<Response> asyncPreResetPubKey(PreResetPubKeyRequest request, ICallback callback)Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
request | Yes | PreResetPubKeyRequest | The request to initiate the public key reset. |
callback | Yes | ICallback | The callback that receives the transaction hash and response. |
Response
| Field | Type | Description |
|---|---|---|
result | MychainBase<Response> | Contains a response field. |
Example
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
MychainBase<Response> response = sdk.getAccountService().asyncPreResetPubKey(
PreResetPubKeyRequest.build(accId, params),
new ICallback() {
@Override
public void onResponse(String txHash, Response response) {
// Handle pre-reset confirmation
}
});PreResetPubKeyRequest
| Field | Type | Description |
|---|---|---|
acctId | Identity | The identity of the account whose public key will be reset. |
mychainParams | MychainParams | Common parameters, including gas limit and signing keys. |
Reset public keys
Call resetPubKey or asyncResetPubKey after a successful preResetPubKey call to complete the key rotation.
resetPubKey
Completes the public key reset synchronously.
Signature
public MychainBase<ReplyTransactionReceipt> resetPubKey(ResetPubKeyRequest request)Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
request | Yes | ResetPubKeyRequest | The request to complete the public key reset. |
Response
| Field | Type | Description |
|---|---|---|
result | MychainBase<ReplyTransactionReceipt> | Contains a response field with the transaction receipt. |
Example
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
MychainBase<Response> response = sdk.getAccountService().resetPubKey(
ResetPubKeyRequest.build(testAccount1.getIdentity(), authMap, params));asyncResetPubKey
Completes the public key reset asynchronously.
Signature
public MychainBase<Response> asyncResetPubKey(ResetPubKeyRequest request, ICallback callback)Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
request | Yes | ResetPubKeyRequest | The request to complete the public key reset. |
callback | Yes | ICallback | The callback that receives the transaction hash and response. |
Response
| Field | Type | Description |
|---|---|---|
result | MychainBase<Response> | Contains a response field. |
Example
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
MychainBase<Response> response = sdk.getAccountService().asyncResetPubKey(
ResetPubKeyRequest.build(testAccount1.getIdentity(), beforeAuthMap, params),
new ICallback() {
@Override
public void onResponse(String txHash, Response response) {
System.out.println("async reset pubkey, txHash:" + txHash
+ ", result: " + response.getErrorCode());
}
});ResetPubKeyRequest
| Field | Type | Description |
|---|---|---|
acctId | Identity | The identity of the account whose public key is being reset. |
mychainParams | MychainParams | Common parameters, including gas limit and signing keys. |
Update weights
Each account has an auth map (AuthMap) that maps public key hex strings to integer weights. The total weight of the signing keys used in a transaction must meet the account's threshold to authorize operations.
updateAuthMap
Updates the auth map (key weights) for an account synchronously.
Signature
public MychainBase<ReplyTransactionReceipt> updateAuthMap(UpdateAuthMapRequest request)Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
request | Yes | UpdateAuthMapRequest | The request to update the auth map. |
Response
| Field | Type | Description |
|---|---|---|
result | MychainBase<ReplyTransactionReceipt> | Contains a response field with the transaction receipt. |
Example
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
MychainBase<ReplyTransactionReceipt> response = sdk.getAccountService().updateAuthMap(
UpdateAuthMapRequest.build(testAccount1.getIdentity(), beforeAuthMap, params));asyncUpdateAuthMap
Updates the auth map (key weights) for an account asynchronously.
Signature
public MychainBase<Response> asyncUpdateAuthMap(UpdateAuthMapRequest request, ICallback callback)Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
request | Yes | UpdateAuthMapRequest | The request to update the auth map. |
callback | Yes | ICallback | The callback that receives the transaction hash and response. |
Response
| Field | Type | Description |
|---|---|---|
result | MychainBase<Response> | Contains a response field. |
Example
The following example fetches the current auth map, increments every key's weight by 10, then submits the update.
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
AuthMap beforeAuthMap = sdk.getQueryService()
.queryAccount(testAccount1.getIdentity().hexStrValue())
.getData().getAccount().getAuthMap();
for (Map.Entry<String, Integer> entry : beforeAuthMap.getAuthMap().entrySet()) {
beforeAuthMap.updateAuth(entry.getKey(), entry.getValue() + 10);
}
MychainBase<Response> result = sdk.getAccountService().asyncUpdateAuthMap(
UpdateAuthMapRequest.build(testAccount1.getIdentity(), beforeAuthMap, params),
new ICallback() {
@Override
public void onResponse(String txHash, Response response) {
System.out.println("async update auth map, txHash:" + txHash
+ ", result: " + response.getErrorCode());
}
});UpdateAuthMapRequest
| Field | Type | Description |
|---|---|---|
acctId | Identity | The identity of the account to update. |
authMap | AuthMap | The new auth map. Each entry maps a public key hex string to an integer weight. Use authMap.updateAuth(pubKeyHex, weight) to set individual entries. |
mychainParams | MychainParams | Common parameters, including gas limit and signing keys. |
Freeze accounts
Only an account with admin privileges can freeze another account. Pass the admin account's identity as the from parameter. If the calling identity lacks sufficient permissions, the transaction fails with a permission error.
freezeAccount
Freezes an account synchronously. A frozen account cannot initiate transactions.
Signature
public MychainBase<ReplyTransactionReceipt> freezeAccount(FreezeAccountRequest request)Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
request | Yes | FreezeAccountRequest | The freeze request. |
Response
| Field | Type | Description |
|---|---|---|
result | MychainBase<ReplyTransactionReceipt> | Contains a response field with the transaction receipt. |
Example
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
MychainBase<ReplyTransactionReceipt> result = sdk.getAccountService().freezeAccount(
FreezeAccountRequest.build(adminAccount.getIdentity(), testAccount1.getIdentity(), params));asyncFreezeAccount
Freezes an account asynchronously.
Signature
public MychainBase<Response> asyncFreezeAccount(FreezeAccountRequest request, ICallback callback)Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
request | Yes | FreezeAccountRequest | The freeze request. |
callback | Yes | ICallback | The callback that receives the transaction hash and response. |
Response
| Field | Type | Description |
|---|---|---|
result | MychainBase<Response> | Contains a response field. |
Example
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
MychainBase<Response> result = sdk.getAccountService().asyncFreezeAccount(
FreezeAccountRequest.build(adminAccount.getIdentity(), testAccount1.getIdentity(), params),
new ICallback() {
@Override
public void onResponse(String txHash, Response response) {
assertNotNull(txHash);
assertTrue(response.getErrorCode().isSuccess());
}
});FreezeAccountRequest
| Field | Type | Description |
|---|---|---|
from | Identity | The identity of the admin account initiating the freeze. |
to | Identity | The identity of the account to freeze. |
mychainParams | MychainParams | Common parameters, including gas limit and signing keys. |
Unfreeze accounts
Only an account with admin privileges can unfreeze an account. Pass the admin account's identity as the from parameter.
unFreezeAccount
Unfreezes an account synchronously.
Signature
public MychainBase<ReplyTransactionReceipt> unFreezeAccount(UnfreezeAccountRequest request)Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
request | Yes | UnfreezeAccountRequest | The unfreeze request. |
Response
| Field | Type | Description |
|---|---|---|
result | MychainBase<ReplyTransactionReceipt> | Contains a response field with the transaction receipt. |
Example
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
MychainBase<ReplyTransactionReceipt> result2 = sdk.getAccountService()
.unFreezeAccount(
UnfreezeAccountRequest.build(adminAccount.getIdentity(),
testAccount1.getIdentity(), params));asyncUnFreezeAccount
Unfreezes an account asynchronously.
Signature
public MychainBase<Response> asyncUnFreezeAccount(UnfreezeAccountRequest request, ICallback callback)Request parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
request | Yes | UnfreezeAccountRequest | The unfreeze request. |
callback | Yes | ICallback | The callback that receives the transaction hash and response. |
Response
| Field | Type | Description |
|---|---|---|
result | MychainBase<Response> | Contains a response field. |
Example
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
MychainBase<Response> result2 = sdk.getAccountService().asyncUnFreezeAccount(
UnfreezeAccountRequest.build(adminAccount.getIdentity(), testAccount1.getIdentity(), params),
new ICallback() {
@Override
public void onResponse(String txHash, Response response) {
assertNotNull(txHash);
assertTrue(response.getErrorCode().isSuccess());
}
});UnfreezeAccountRequest
| Field | Type | Description |
|---|---|---|
from | Identity | The identity of the admin account initiating the unfreeze. |
to | Identity | The identity of the account to unfreeze. |
mychainParams | MychainParams | Common parameters, including gas limit and signing keys. |