链上账户

createAccount

创建账户,使用已经激活的账户来创建一个新的账户。

createAccount(ownerAddress, accountAddress)

参数

  1. ownerAddress(String)*

创建者账号地址,如果创建者账号有足够的通过质押TRX获得的带宽,那么创建账户只会消耗带宽,否则,会烧掉0.1个TRX来支付带宽费用,同时,需要支付1 TRX的创建费用, Base58check 格式或 HEX 格式。

  1. accountAddress(String)*

所创建的账户地址,Base58check 格式或 HEX 格式。

返回

TransactionExtention,包括执行结果。

异常

IllegalException,创建账户失败时抛出此异常。

示例

TransactionExtention transaction = wrapper.createAccount("TMmbeRPnFhXC7BPLaF2M1HCsoE4jwZNB7b","TD9tMPSfBJ3To8s71vdBz2BLT2wwBNWyLc");
Transaction signedTxn = wrapper.signTransaction(transaction);
String ret = wrapper.broadcastTransaction(signedTxn);

执行结果:

6f85a7721cc9acd80a3de5e41ffdbc8c1eb65304732836321165daa9efc6e235

getAccount

通过账户地址获取账户信息。

getAccount(address)

参数

  1. address(String)*

帐户地址,Base58check 格式或 HEX 格式。

返回

Account 对象。

示例

wrapper.getAccount("TKwVM5tsELuTE3a5SUCWiQyVtEgxejL5Wj");

执行结果:

account_name: "123"
  address: "A\"\355b\226~\320\322\030k/\3069\327\227-\027*\225\310U"
  balance: 3876000001
  create_time: 1608876732000
  latest_opration_time: 1611729843000
  asset_issued_name: "lsp1"
  latest_consume_free_time: 1611729843000
  account_resource {
  }
  owner_permission {
    ...
  }
  active_permission {
    ...
  }
  assetV2 {
    ...
  }
  asset_issued_ID: "1000204"
  free_asset_net_usageV2 {
    ...
  }

updateAccount

修改账户的名称,只有在账户名称为空的情况下才可以修改。

updateAccount(address, accountName)

参数

  1. address(String)*

需要修改名称的账户地址,Base58check 格式或 HEX 格式。

  1. accountName(String)*

所设置的账号的名称。

返回

TransactionExtention,包括执行结果。

异常

IllegalException,修改账户名称失败时抛出此异常。

示例

TransactionExtention transaction = wrapper.updateAccount("TJ3Zyr26kzS8wRGz7aWYGgenMcqkUuPzLf","name");
Transaction signedTxn = wrapper.signTransaction(transaction);
String ret = wrapper.broadcastTransaction(signedTxn);

执行结果:

8178774ae66b12b72fe5c3db6ec864e9a959bfee2c470af56701ae498288c014

accountPermissionUpdate

修改账户权限,包括 owner ,witness ,active 三种权限级别。

accountPermissionUpdate(contract)

参数

  1. contract(AccountPermissionUpdateContract)*

AccountPermissionUpdateContract 对象。

返回

TransactionExtention 对象。

异常

IllegalException,修改账户权限失败时抛出此异常。

异常

AccountPermissionUpdateContract.Builder builder = AccountPermissionUpdateContract.newBuilder();
Permission ownerPermission = null;
Permission.Builder builderOwner = Permission.newBuilder();
builderOwner.setTypeValue(0);
builderOwner.setPermissionName("owner");
builderOwner.setThreshold(1);

Common.Key.Builder keyOwner = Common.Key.newBuilder();
keyOwner.setAddress(wrapper.parseAddress("4122ED62967ED0D2186B2FC639D7972D172A95C855"));
keyOwner.setWeight(1);
builderOwner.addKeys(keyOwner);
ownerPermission = builderOwner.build();

Permission activePermissions = null;
Permission.Builder builderActive = Permission.newBuilder();
builderActive.setTypeValue(2);
builderActive.setThreshold(1);
builderActive.setPermissionName("active0");
builderActive.setOperations(wrapper.parseAddress("7fff1fc0037e0000000000000000000000000000000000000000000000000000"));
       
Common.Key.Builder keyActive = Common.Key.newBuilder();
keyActive.setAddress(wrapper.parseAddress("4122ED62967ED0D2186B2FC639D7972D172A95C855"));
keyActive.setWeight(1);

builderActive.addKeys(keyActive);
activePermissions = builderActive.build();

builder.setOwner(ownerPermission);
builder.addActives(activePermissions);
builder.setOwnerAddress(wrapper.parseAddress("4122ED62967ED0D2186B2FC639D7972D172A95C855"));

TransactionExtention transaction = wrapper.accountPermissionUpdate(builder.build());
Transaction signedTxn = wrapper.signTransaction(transaction);
String ret = wrapper.broadcastTransaction(signedTxn);

执行结果:

f055632620e3c16d6376ecdcee8e3b077e203f4d52e2c5e29228d44d419bed4c