Skip to content

@acala-network/chopsticks-coreDocs


@acala-network/chopsticks-core / Blockchain

Class: Blockchain

Local blockchain which provides access to blocks, txpool and methods to manipulate the chain such as build blocks, submit extrinsics, xcm and more!

Example

ts
const chain = new Blockchain({
 api,
 buildBlockMode: BuildBlockMode.Manual,
 inherentProviders,
 header: {
   hash: blockHash,
   number: Number(header.number),
 },
 mockSignatureHost: true,
 allowUnresolvedImports: true,
 registeredTypes: {},
})
// build a block
chain.newBlock()

Constructors

new Blockchain()

new Blockchain(options): Blockchain

Parameters

options: Options

Options for instantiating the blockchain

Returns

Blockchain

Defined in

packages/core/src/blockchain/index.ts:129

Properties

allowUnresolvedImports

readonly allowUnresolvedImports: boolean

Allow wasm unresolved imports.

Defined in

packages/core/src/blockchain/index.ts:85


api

readonly api: Api

API instance, for getting on-chain data.

Defined in

packages/core/src/blockchain/index.ts:79


db

readonly db: undefined | Database

Datasource for caching storage and blocks data.

Defined in

packages/core/src/blockchain/index.ts:81


headState

readonly headState: HeadState

For subscribing and managing the head state.

Defined in

packages/core/src/blockchain/index.ts:99


mockSignatureHost

readonly mockSignatureHost: boolean

Enable mock signature. Any signature starts with 0xdeadbeef and filled by 0xcd is considered valid

Defined in

packages/core/src/blockchain/index.ts:83


offchainWorker

readonly offchainWorker: undefined | OffchainWorker

Defined in

packages/core/src/blockchain/index.ts:101


processQueuedMessages

readonly processQueuedMessages: boolean = true

Defined in

packages/core/src/blockchain/index.ts:103


registeredTypes

readonly registeredTypes: RegisteredTypes

Polkadot.js custom types registration.

Defined in

packages/core/src/blockchain/index.ts:88

Accessors

get head(): Block

Returns

Block

Defined in

packages/core/src/blockchain/index.ts:178


runtimeLogLevel

get runtimeLogLevel(): number

set runtimeLogLevel(level): void

Parameters

level: number

Returns

number

Defined in

packages/core/src/blockchain/index.ts:186


txPool

get txPool(): TxPool

Returns

TxPool

Defined in

packages/core/src/blockchain/index.ts:182

Methods

blocksInMemory()

blocksInMemory(): Block[]

Get all blocks in memory.

Returns

Block[]

Defined in

packages/core/src/blockchain/index.ts:311


buildRegistry()

buildRegistry(metadata, version): Promise<TypeRegistry>

Parameters

metadata: `0x${string}`

version: RuntimeVersion

Returns

Promise<TypeRegistry>

Defined in

packages/core/src/blockchain/index.ts:195


close()

close(): Promise<void>

Close the db and disconnect api.

Returns

Promise<void>

Defined in

packages/core/src/blockchain/index.ts:539


dryRunDmp()

dryRunDmp(dmp, at?): Promise<[`0x${string}`, null | `0x${string}`][]>

Dry run dmp messages in block at. Return the storage diff.

Parameters

dmp: DownwardMessage[]

at?: `0x${string}`

Returns

Promise<[`0x${string}`, null | `0x${string}`][]>

Defined in

packages/core/src/blockchain/index.ts:473


dryRunExtrinsic()

dryRunExtrinsic(extrinsic, at?): Promise<object>

Dry run extrinsic in block at.

Parameters

extrinsic: `0x${string}` | object

at?: `0x${string}`

Returns

Promise<object>

outcome

outcome: ApplyExtrinsicResult

storageDiff

storageDiff: [`0x${string}`, null | `0x${string}`][]

Defined in

packages/core/src/blockchain/index.ts:426


dryRunHrmp()

dryRunHrmp(hrmp, at?): Promise<[`0x${string}`, null | `0x${string}`][]>

Dry run hrmp messages in block at. Return the storage diff.

Parameters

hrmp: Record<number, HorizontalMessage[]>

at?: `0x${string}`

Returns

Promise<[`0x${string}`, null | `0x${string}`][]>

Defined in

packages/core/src/blockchain/index.ts:451


dryRunUmp()

dryRunUmp(ump, at?): Promise<[`0x${string}`, null | `0x${string}`][]>

Dry run ump messages in block at. Return the storage diff.

Parameters

ump: Record<number, `0x${string}`[]>

at?: `0x${string}`

Returns

Promise<[`0x${string}`, null | `0x${string}`][]>

Defined in

packages/core/src/blockchain/index.ts:492


getBlock()

getBlock(hash?): Promise<undefined | Block>

Get block by hash.

Parameters

hash?: `0x${string}`

Returns

Promise<undefined | Block>

Defined in

packages/core/src/blockchain/index.ts:275


getBlockAt()

getBlockAt(number?): Promise<undefined | Block>

Get block by number.

Parameters

number?: null | number

Returns

Promise<undefined | Block>

Defined in

packages/core/src/blockchain/index.ts:250


getInherents()

getInherents(): InherentProvider[]

Get inherents of head.

Returns

InherentProvider[]

Defined in

packages/core/src/blockchain/index.ts:532


loadBlockFromDB()

loadBlockFromDB(hashOrNumber): Promise<undefined | Block>

Try to load block from db and register it. If pass in number, get block by number, else get block by hash.

Parameters

hashOrNumber: number | `0x${string}`

Returns

Promise<undefined | Block>

Defined in

packages/core/src/blockchain/index.ts:219


newBlock()

newBlock(params?): Promise<Block>

Build a new block with optional params. Use this when you don't have all the BuildBlockParams

Parameters

params?: Partial<BuildBlockParams>

Returns

Promise<Block>

Defined in

packages/core/src/blockchain/index.ts:403


newBlockWithParams()

newBlockWithParams(params): Promise<Block>

Build a new block with BuildBlockParams.

Parameters

params: BuildBlockParams

Returns

Promise<Block>

Defined in

packages/core/src/blockchain/index.ts:411


onNewBlock()

onNewBlock(block): Promise<void>

Parameters

block: Block

Returns

Promise<void>

Defined in

packages/core/src/blockchain/index.ts:332


saveBlockToDB()

saveBlockToDB(block): Promise<void>

Parameters

block: Block

Returns

Promise<void>

Defined in

packages/core/src/blockchain/index.ts:200


setHead()

setHead(block): Promise<void>

Set block as head.

Parameters

block: Block

Returns

Promise<void>

Defined in

packages/core/src/blockchain/index.ts:340


submitDownwardMessages()

submitDownwardMessages(dmp): void

Parameters

dmp: DownwardMessage[]

Returns

void

Defined in

packages/core/src/blockchain/index.ts:388


submitExtrinsic()

submitExtrinsic(extrinsic): Promise<`0x${string}`>

Submit extrinsic to txpool.

Parameters

extrinsic: `0x${string}`

Returns

Promise<`0x${string}`>

Defined in

packages/core/src/blockchain/index.ts:360


submitHorizontalMessages()

submitHorizontalMessages(id, hrmp): void

Parameters

id: number

hrmp: HorizontalMessage[]

Returns

void

Defined in

packages/core/src/blockchain/index.ts:394


submitUpwardMessages()

submitUpwardMessages(id, ump): void

Parameters

id: number

ump: `0x${string}`[]

Returns

void

Defined in

packages/core/src/blockchain/index.ts:382


unregisterBlock()

unregisterBlock(block): Promise<void>

Remove block from memory and db.

Parameters

block: Block

Returns

Promise<void>

Defined in

packages/core/src/blockchain/index.ts:318


upcomingBlocks()

upcomingBlocks(): Promise<number>

Get the upcoming blocks.

Returns

Promise<number>

Defined in

packages/core/src/blockchain/index.ts:419


validateExtrinsic()

validateExtrinsic(extrinsic, source): Promise<TransactionValidity>

Validate extrinsic by calling TaggedTransactionQueue_validate_transaction.

Parameters

extrinsic: `0x${string}`

source: "0x00" | "0x01" | "0x02" = '0x02'

Returns

Promise<TransactionValidity>

Defined in

packages/core/src/blockchain/index.ts:372