Skip to content

Latest commit

 

History

History
197 lines (145 loc) · 11.1 KB

specialized-types.md

File metadata and controls

197 lines (145 loc) · 11.1 KB

Specialized Types

An AccountId is composed of a <shardNum>.<realmNum>.<accountNum> (eg. 0.0.10).

  • Shard number (shardNum) represents the shard number (shardId). It will default to 0 today, as Hedera only performs in one shard.
  • Realm number (realmNum) represents the realm number (realmId). It will default to 0 today, as realms are not yet supported.
  • Account represents either an account number or an account alias
    • Account number (accountNum) represents the account number (accountId)
    • Account alias (alias) represented by the public key bytes
      • The public key bytes are the result of serializing a protobuf Key message for any primitive key type
      • Currently, only primitive key bytes are supported as an alias
      • Threshold keys, key list, contract ID, and delegatable_contract_id are not supported
      • The alias can only be used in place of an account ID in transfer transactions in its current version

Together these values make up your AccountId. When an AccountId is specified, be sure all three values are included.

Constructor

ConstructorTypeDescription
new AccountId(<shardNum>,<realmNum>,<accountNum>)long, long, longConstructs an AccountId with 0 for shardNum and realmNum (e.g., 0.0.<accountNum>)

Methods

MethodsTypeDescription
AccountId.fromString(<account>)StringConstructs an AccountId from a string formatted as <shardNum>.<realmNum>.<accountNum>
AccountId.fromEvmAddress(<address>)StringConstructs an AccountId from a solidity address in string format
AccountId.fromBytes(bytes)byte[]Constructs an AccountId from bytes
AccountId.toSolidityAddress()StringConstructs a solidity address from AccountID
AccountId.toString()StringConstructs an AccountID from string
AccountId.aliasKeyPublicKeyThe alias key of the AccountID
AccountId.aliasEvmAddressEVM addressThe EVM address of the AccountID
AccountId.toBytes()byte[]Constructs an AccountID from bytes

Example

{% tabs %} {% tab title="Java" %}

AccountId accountId = new AccountId(0 ,0 ,10);
System.out.println(accountId);

// Constructs an accountId from String
AccountId accountId = AccountId.fromString("0.0.10");
System.out.println(accountId);

{% endtab %}

{% tab title="JavaScript" %}

const accountId = new AccountId(100);
console.log(`${accountId}`);

// Construct accountId from String
const accountId = AccountId.fromString(`100`);
console.log(`${accountId}`);

{% endtab %}

{% tab title="Go" %}

hedera.AccountIDFromString("0.0.3")

{% endtab %} {% endtabs %}

A FileId is composed of a <shardNum>.<realmNum>.<fileNum> (eg. 0.0.15).

  • shardNum represents the shard number (shardId). It will default to 0 today, as Hedera only performs in one shard.
  • realmNum represents the realm number (realmId). It will default to 0 today, as realms are not yet supported.
  • fileNum represents the file number

Together these values make up your accountId. When an FileId is requested, be sure all three values are included.

Constructor

ConstructorTypeDescription
new FileId(<shardNum>,<realmNum>,<fileNum>)long, long, longConstructs a FileId with 0 for shardNum and realmNum (e.g., 0.0.<fileNum>)

Methods

MethodsTypeDescription
FileId.fromString()String

Constructs an FileId from a string formatted as

<shardNum>.<realmNum>.<fileNum>

FileId.fromSolidityAddress()StringConstructs an FileId from a solidity address in string format
FileId.ADDRESS_BOOKFileIdThe public node address book for the current network
FileId.EXCHANGE_RATESFileIdThe current exchange rate of HBAR to USD
FileId.FEE_SCHEDULEFileIdThe current fee schedule for the network

Example

{% tabs %} {% tab title="Java" %}

FileId fileId = new FileId(0,0,15);
System.out.println(fileId);

//Constructs a FileId from string
FileId fileId = FileId.fromString("0.0.15");
System.out.println(fileId);

{% endtab %}

{% tab title="JavaScript" %}

const newFileId = new FileId(100);
console.log(`${newFileId}`);

//Construct a fileId from a String
const newFileIdFromString = FileId.fromString(`100`); 
console.log(`${newFileIdFromString}`);

{% endtab %}

{% tab title="Go" %}

hedera.FileIDFromString("0.0.3")

{% endtab %} {% endtabs %}

A ContractId is composed of a <shardNum>.<realmNum>.<contractNum> (eg. 0.0.20).

  • shardNum represents the shard number (shardId). It will default to 0 today, as Hedera only performs in one shard.
  • realmNum represents the realm number (realmId). It will default to 0 today, as realms are not yet supported.
  • contractNum represents the contract number

Together these values make up your ContractId. When an ContractId is requested, be sure all three values are included. ContractId's are automatically assigned when you create a new smart contract.

Constructor

Constructor Type Description
new ContractId(<shardNum>,<realmNum>,<contractNum>) long, long, long Constructs a ContractId with 0 for shardNum and realmNum (e.g., 0.0.<contractNum>)

Methods

MethodsTypeDescription
ContractId.fromString(<account>)String

Constructs a ContractId from a string formatted as

<shardNum>.<realmNum>.<contractNum>

ContractId.fromSolidityAddress(<address>)[deprecated use ConractId.fromEvmAddress()]StringConstructs a ContractId from a solidity address in string format [deprecated use ContractId.fromEvmAddres()]
ContractId.toSolidityAddress(<contractId>)StringContruct a Solidity address from a Hedera contract ID
ContractId.fromEvmAddress(<shard>, <realm>, <evmAddress>)long, long, StringConstructs a ContractId from evm address

Example

{% tabs %} {% tab title="Java" %}

ContractId contractId = new ContractId(0,0,20);
System.out.println(contractId);

// Constructs a ContractId from string
ContractId contractId = ContractId.fromString("0.0.20");
System.out.println(contractId);

{% endtab %}

{% tab title="JavaScript" %}

const newContractId = new ContractId(100);
console.log(`${newContractId}`);

// Construct a contractId from a String
const newContractId = ContractId.fromString(`100`); 
console.log(`${newContractId}`);

{% endtab %}

{% tab title="Go" %}

hedera.ContractIDFromString("0.0.3")

{% endtab %} {% endtabs %}

A topicId is composed of a <shardNum>.<realmNum>.<topicNum> (eg. 0.0.100).

  • shardNum represents the shard number (shardId). It will default to 0 today, as Hedera only performs in one shard.
  • realmNum represents the realm number (realmId). It will default to 0 today, as realms are not yet supported.
  • topicNum represents the topic number (topicId)

Constructor

ConstructorTypeDescription
new ConsensusTopicId(<shardNum>,<realmNum>,<topicNum>)long, long, longConstructs a TopicId with 0 for shardNum and realmNum (e.g., 0.0.<topicNum>)
MethodsTypeDescription
fromString(<topic>)StringConstructs a topic ID from a String
ConsensusTopicId.toString()Constructs a topic ID to String format

Example

{% tabs %} {% tab title="Java" %}

ConsensusTopicId topicId = new ConsensusTopicId(0,0,100);
System.out.println(topicId)

{% endtab %}

{% tab title="JavaScript" %}

const topicId = new ConsensusTopicId(0,0,100);
console.log(topicId)

{% endtab %}

{% tab title="Go" %}

hedera.TopicIDFromString("0.0.3")

{% endtab %} {% endtabs %}