Addresses
Address#
Overview#
Changes within the aelf blockchain occur through the execution of transactions. An address within aelf identifies a participant in a transaction, either as the sender or the recipient. The sender is denoted as From, while the recipient is denoted as To.
From can represent:
To is exclusively a Contract Address, indicating that the transaction sender intends to execute a specific method within that smart contract.
For further details on each type of address in the aelf blockchain, please see below.
User Address#
A User Address in aelf is generated from a unique key pair owned by a real user of the blockchain. Here’s how it works:
Key Pair Generation:#
1public interface IAElfAsymmetricCipherKeyPair2{3byte[] PrivateKey { get; }4byte[] PublicKey { get; }5}
Currently, aelf blockchain utilizes ECKeyPair for this purpose, similar to many other blockchain systems.
Generating a Key Pair:#
1aelf-command create
Using dApp SDK:#
For dApp developers, the aelf JavaScript SDK js-sdk` offers a method based on bip39 for deterministic key pair generation:
1import Aelf from 'aelf-sdk';2Aelf.wallet.createNewWallet();
This method returns an object with the mnemonic, key pair, and address encoded in base58.
Generating an Address#
When you create a new wallet using the aelf-sdk, it will return an object with three important parts:
In aelf, we usually encode the address in a format called base58. The address is derived from the public key by taking the first 30 bytes of its double SHA-256 hash. Here's how you can get the address from the public key using the aelf-sdk:
1import Aelf from 'aelf-sdk';2const address = Aelf.wallet.getAddressFromPubKey(pubKey);
Address Representation:#
1option csharp_namespace = "AElf.Types";2message Address3{4bytes value = 1;5}
In summary, a User Address in aleft blockchain is fundamental for identifying users and interacting with the blockchain securely and effectively.
Contract Address#
A Contract Address in aelf blockchain uniquely identifies a Smart Contract. Here’s how it’s created:
Here’s how you can build a Contract Address in aelf:
1private static Address BuildContractAddress(Hash chainId, long serialNumber)2{3var hash = HashHelper.ConcatAndCompute(chainId, HashHelper.ComputeFrom(serialNumber));4return Address.FromBytes(hash.ToByteArray());5}6public static Address BuildContractAddress(int chainId, long serialNumber)7{8return BuildContractAddress(HashHelper.ComputeFrom(chainId), serialNumber);9}
In essence, a Contract Address in aelf blockchain ensures each Smart Contract can be uniquely identified and interacted with securely across the network.
Contract Virtual Address#
In the aelf blockchain, every contract has the capability to create additional virtual addresses based on its main Address. These virtual addresses are known as Virtual Addresses.
In summary, Virtual Addresses in aelf blockchain enhance the flexibility and security of contract interactions by providing unique identifiers derived from the main contract Address.
Edited on: 14 July 2024 05:07:57 GMT+0