Account

A PolySmartChain account is an entity with PSC balance that can send transactions on PolySmartChain. The account can be controlled by the user or can be deployed as a smart contract.

Account Type

PolySmartChain has two account types.

  • Externally Held - Owner control of the private key

  • Contracts - A type of smart contract controlled by code and deployed on the network. Learn about smart contracts.

Both account types can:

  • Receiving, holding and sending PSC and token

  • Interacting with deployed smart contracts

Main Differences

Externally Held

  • Account creation is free

  • Can initiate transactions

  • Only PSC and token can be traded between all external accounts

Contracts

  • There are costs associated with creating contracts because of the need to use network storage space

  • Transactions can only be sent when they are received

  • Transactions initiated from an external account to a contract account can trigger code that can perform a variety of actions, such as transferring tokens or even creating new contracts

Understanding Accounts

PolySmartChain accounts have four fields:

  • nonce – A counter that shows the number of transactions sent from the account. This will ensure that transactions are processed only once. In a contract account, this number represents the number of contracts created for that account.

  • balance – The number of Wei this address has. Wei is the unit of count for Ether, and each ETH has 1e+18 Wei.

  • codeHash - This hash represents the account code on the PolySmartChain Virtual Machine (EVM). The contract account has programmed pieces of code that can perform different operations. If the account receives a message call, this EVM code is executed. Unlike other account fields, it cannot be changed. All code snippets are stored in the status database under the corresponding hash for subsequent retrieval. This hash is called codeHash. For all external accounts, the codeHash field is a hash of the empty string.

  • storageRoot – Sometimes referred to as a storage hash. The 256-bit hash of the Merkle Patricia trie root node has encoded the stored contents of the account (256-bit integer value mapping) and is encoded as a Trie as a mapped bit integer key from the 256 Keccak 256-bit hash for the RLP-encoded 256-bit integer value. This Trie encodes the hash of this account's stored content, which is empty by default.

Externally held accounts and key pairs

Accounts consist of public and private key encryption pairs. They help prove that the transaction was actually signed by the sender and prevent forgery. Your private key is the key you use to sign transactions, so it safeguards your management of the funds associated with your account. You never actually hold the cryptocurrency, you hold the private key - the funds are always on PolySmartChain's books.

This will prevent malicious participants from broadcasting fake transactions, as you can always verify the sender of the transaction.

If Alice wants to send PSC from her own account to Bob's account, Alice needs to create a transaction request and send it to the network for verification. Ethernet's use of public key encryption ensures that Alice can prove that she initiated the transaction request in the first place. Without encryption, the malicious adversary Eve could simply broadcast publicly a request that looks like "send 5 PSC from Alice's account to Eve's account". And no one can prove that it did not come from Alice.

Account Creation

When you want to create an account, most libraries will generate a random private key.

The private key consists of 64 hexadecimal characters and can be stored encrypted with a password.

For example:

fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036415f

Generate the public key from the private key by using the elliptic curve digital signature algorithm. You can get a public address for your account by getting the last 20 bytes of the Keccak-256 hash of the public key and adding 0x in front of the checksum.

The following is an example of creating an account in the console by using GPSC's personal_newAccount

1> personal.newAccount()2Passphrase:3Repeat passphrase:4"0x5e97870f263700f46aa00d967821199b9bc5a120"5
6> personal.newAccount("h4ck3r")7"0x3d80b31a78c30fc628f20b2c89d7ddbf6e53cedc"8

It is possible to obtain a public key from your private key, but you cannot obtain a private key from a public key. This means that it is critical to keep the private key secure, as the name suggests PRIVATE.

You need a private key to sign messages and transactions and output a signature. Others can then use the signature to obtain your public key and prove the authorship of the message. In your application, you can use the javascript library to send transactions to the network.

Contract Accounts

The contract account also has a hexadecimal address consisting of 42 characters:

For example:

0x06012c8cf97bead5deae237070f9587f8e7a266d

The contract address is usually given when the contract is deployed to the PolySmartChain blockchain. The address is generated from the creator's address and the number of transactions sent from the creator's address ("nonce").

Note on the wallet

An account is different from a wallet. An account is a user-owned key and address pair for an ethereum account. A wallet is an interface, or application, that allows you to interact with your PolySmartChain account.

Expanding Resources

Last updated