Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

v7.0.6 - New Account Class

Compare
Choose a tag to compare
@holgerd77 holgerd77 released this 08 Oct 11:31
· 34 commits to master since this release
c1787c1

New Account class

This release adds a new Account class intended as a modern replacement for ethereumjs-account. It has a shape of Account(nonce?: BN, balance?: BN, stateRoot?: Buffer, codeHash?: Buffer).

Instantiation

The static factory methods assist in creating an Account object from varying data types: Object: fromAccountData, RLP: fromRlpSerializedAccount, and Array: fromValuesArray.

Methods: isEmpty(): boolean, isContract(): boolean, serialize(): Buffer

Example usage:

import { Account, BN } from 'ethereumjs-util'

const account = new Account(
  new BN(0), // nonce, default: 0
  new BN(10).pow(new BN(18)), // balance, default: 0
  undefined, // stateRoot, default: KECCAK256_RLP (hash of RLP of null)
  undefined, // codeHash, default: KECCAK256_NULL (hash of null)
)

For more info see the documentation, examples of usage in test/account.spec.ts or PR #275.

New export: TypeScript types

A new file with helpful TypeScript types has been added to the exports of this project, see PR #275.

In this release it contains BNLike, BufferLike, and TransformableToBuffer.

Address.toBuffer()

The Address class has as a new method address.toBuffer() that will give you a copy of the underlying address.buf (PR #277).

toBuffer() now converts TransformableToBuffer

The toBuffer() exported function now additionally converts any object with a toBuffer() method (PR #277).