This topic mainly introduces some interface parameters involved in operating accounts.
Create accounts
createAccount
You can call this synchronous operation to create an account.
public MychainBase<ReplyTransactionReceipt> createAccount(CreateAccountRequest request)
Name |
Required |
Type |
Description |
request |
true |
CreateAccountRequest |
The request to create an account. |
Response field |
Field type |
Description |
result |
MychainBase< ReplyTransactionReceipt> |
MychainBaseResult contains a response type. |
MychainBase<ReplyTransactionReceipt> result = sdk.getAccountService().createAccount(
CreateAccountRequest.build(
adminAccount.getIdentity(), testAccount1, params
)
);
asyncCreateAccount
You can call this asynchronous operation to create an account.
public MychainBase<Response> asyncCreateAccount(CreateAccountRequest request, ICallback callback)
Name |
Required |
Type |
Description |
request |
true |
CreateAccountRequest |
The request to create an account. |
callback |
true |
ICallback |
The callback function. |
Response field |
Field type |
Description |
result |
MychainBaseResult |
MychainBaseResult contains a response type. |
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
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.
public MychainBase<ReplyTransactionReceipt> transferBalance(TransferBalanceRequest request)
Name |
Required |
Type |
Description |
request |
true |
TransferBalanceRequest |
The transfer request. |
Response field |
Field type |
Description |
result |
MychainBaseResult |
MychainBaseResult contains a response type. |
// build params
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
//transfer balance
MychainBase<ReplyTransactionReceipt> result = sdk.getAccountService().transferBalance(
TransferBalanceRequest.build(testAccount1.getIdentity(),
testAccount2.getIdentity(),
new BigInteger(transferAmount+""),
params
)
);
asyncTransferBalance
You can call this asynchronous operation to perform a transfer.
public MychainBase<Response> asyncTransferBalance(TransferBalanceRequest request, ICallback callback)
Name |
Required |
Type |
Description |
request |
true |
TransferBalanceRequest |
The transfer request. |
callback |
true |
ICallback |
The callback function. |
Response field |
Field type |
Description |
result |
MychainBaseResult |
MychainBaseResult contains a response type. |
// build params
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
// async transfer balance
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
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.
public MychainBase<ReplyTransactionReceipt> setRecoverKey(SetRecoverKeyRequest request)
Name |
Required |
Type |
Description |
request |
true |
SetRecoverKeyRequest |
The request to set a recovery public key. |
Response field |
Field type |
Description |
result |
MychainBaseResult |
MychainBaseResult contains a response type. |
// build params
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
You can call this asynchronous operation to set the recovery public key.
public MychainBase<Response> asyncSetRecoverKey(SetRecoverKeyRequest request, ICallback callback)
Name |
Required |
Type |
Description |
request |
true |
SetRecoverKeyRequest |
The request to set a recovery public key. |
callback |
true |
ICallback |
The callback function. |
Response field |
Field type |
Description |
result |
MychainBase |
MychainBaseResult contains a response type. |
// build params
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
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.
public MychainBase<ReplyTransactionReceipt> preResetPubKey(PreResetPubKeyRequest request)
Name |
Required |
Type |
Description |
request |
true |
PreResetPubKeyRequest |
The request to pre-reset the public key. |
Response field |
Field type |
Description |
result |
MychainBase |
MychainBaseResult contains a response type. |
// build params
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
// pre reset
MychainBase<ReplyTransactionReceipt> result = sdk.getAccountService().preResetPubKey(PreResetPubKeyRequest.build( acctId, params));
asyncPreResetPubKey
You can call this asynchronous operation to pre-reset the public key.
public MychainBase<Response> asyncPreResetPubKey(PreResetPubKeyRequest request, ICallback callback)
Name |
Required |
Type |
Description |
request |
true |
PreResetPubKeyRequest |
The requests to pre-reset the public key. |
callback |
true |
ICallback |
The callback function. |
Response field |
Field type |
Description |
result |
MychainBase |
MychainBaseResult contains a response type. |
// build params
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) {
}
});
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.
public MychainBase<ReplyTransactionReceipt> resetPubKey(ResetPubKeyRequest request)
Name |
Required |
Type |
Description |
request |
true |
ResetPubKeyTransaction |
The request to reset the public key. |
Response field |
Field type |
Description |
result |
MychainBase |
MychainBaseResult contains a response type. |
// build params
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
// reset public key
MychainBase<Response> response = sdk.getAccountService().resetPubKey(
ResetPubKeyRequest.build(testAccount1.getIdentity(), authMap, params));
asyncResetPubKey
You can call this asynchronous operation to reset the public key.
public MychainBase<Response> asyncResetPubKey(ResetPubKeyRequest request,ICallback callback)
Name |
Required |
Type |
Description |
request |
true |
ResetPubKeyRequest |
The request to reset the public key. |
callback |
true |
ICallback |
The callback function. |
Response field |
Field type |
Description |
result |
MychainBase |
MychainBaseResult contains a response type. |
// build params
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
// reset public key
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
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.
public MychainBase<ReplyTransactionReceipt> updateAuthMap(UpdateAuthMapRequest request)
Name |
Required |
Type |
Description |
request |
true |
UpdateAuthMapRequest |
The request to update the weights. |
Response field |
Field type |
Description |
result |
MychainBase |
MychainBaseResult contains a response type. |
// build params
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
// update authmap
MychainBase<ReplyTransactionReceipt> response = sdk.getAccountService().updateAuthMap(
UpdateAuthMapRequest.build(testAccount1.getIdentity(), beforeAuthMap, params));
asyncUpdateAuthMap
You can call this asynchronous operation to update the weights.
public MychainBase<Response> asyncUpdateAuthMap(UpdateAuthMapRequest request,ICallback callback)
Name |
Required |
Type |
Description |
request |
true |
UpdateAuthMapRequest |
The request to update the weights. |
callback |
true |
ICallback |
The callback function. |
Response field |
Field type |
Description |
result |
MychainBase |
MychainBaseResult contains a response type. |
// build params
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
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.
public MychainBase<ReplyTransactionReceipt> freezeAccount(FreezeAccountRequest request)
Name |
Required |
Type |
Description |
request |
true |
FreezeAccountRequest |
The request to freeze an account. |
Response field |
Field type |
Description |
result |
MychainBase |
MychainBaseResult contains a response type. |
// build params
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
// freeze account
MychainBase<ReplyTransactionReceipt> result = sdk.getAccountService().freezeAccount(
FreezeAccountRequest.build(adminAccount.getIdentity(), testAccount1.getIdentity(),
params))
asyncFreezeAccount
You can call this asynchronous operation to freeze an account.
public MychainBase<Response> asyncFreezeAccount(FreezeAccountRequest request,ICallback callback)
Name |
Required |
Type |
Description |
request |
true |
FreezeAccountRequest |
The request to freeze an account. |
callback |
true |
ICallback |
The callback function. |
Response field |
Field type |
Description |
result |
MychainBase |
MychainBaseResult contains a response type. |
// build params
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
// async freeze account
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
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.
public MychainBase<ReplyTransactionReceipt> unFreezeAccount(UnfreezeAccountRequest request)
Name |
Required |
Type |
Description |
request |
true |
UnfreezeAccountRequest |
The request to unfreeze an account. |
Response field |
Field type |
Description |
result |
MychainBase<ReplyTransactionReceipt> |
MychainBaseResult contains a response type. |
// build params
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
// unfreeze account
MychainBase<ReplyTransactionReceipt> result2 = sdk.getAccountService()
.unFreezeAccount(
UnfreezeAccountRequest.build(adminAccount.getIdentity(),
testAccount1.getIdentity(), params));
asyncUnFreezeAccount
You can call this asynchronous operation to unfreeze an account.
public MychainBase<Response> asyncUnFreezeAccount(UnfreezeAccountRequest request,ICallback callback)
Name |
Required |
Type |
Description |
request |
true |
UnfreezeAccountRequest |
The request to unfreeze an account. |
callback |
true |
ICallback |
The callback function. |
Response field |
Field type |
Description |
result |
MychainBase |
MychainBaseResult contains a response type. |
// build params
MychainParams params = new MychainParams.Builder()
.gas(BigInteger.valueOf(40000))
.privateKeyList(adminPrivateKeys)
.build();
// async unfreeze account
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
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 |