Skip to main content

Mina

o1js / Modules / Mina

Namespace: Mina

Table of contents

Type Aliases

Variables

Functions

Type Aliases

ActionStates

Ƭ ActionStates: Object

Type declaration

NameType
endActionState?Field
fromActionState?Field

Defined in

lib/mina/mina-instance.ts:83


FeePayerSpec

Ƭ FeePayerSpec: PublicKey | { fee?: number | string | UInt64 ; memo?: string ; nonce?: number ; sender: PublicKey } | undefined

Allows you to specify information about the fee payer account and the transaction.

Defined in

lib/mina/mina-instance.ts:54


IncludedTransaction

Ƭ IncludedTransaction: Pick\<PendingTransaction, "transaction" | "toJSON" | "toPretty" | "hash" | "data"> & { status: "included" }

Represents a transaction that has been successfully included in a block.

Defined in

lib/mina/transaction.ts:231


NetworkConstants

Ƭ NetworkConstants: Object

Type declaration

NameTypeDescription
accountCreationFeeUInt64-
genesisTimestampUInt64-
slotTimeUInt64Duration of 1 slot in millisecondw

Defined in

lib/mina/mina-instance.ts:88


PendingTransaction

Ƭ PendingTransaction: Pick\<Transaction, "transaction" | "toJSON" | "toPretty"> & { data?: SendZkAppResponse ; errors: string[] ; hash: string ; status: PendingTransactionStatus ; safeWait: (options?: { interval?: number ; maxAttempts?: number }) => Promise\<RejectedTransaction | IncludedTransaction> ; wait: (options?: { interval?: number ; maxAttempts?: number }) => Promise\<IncludedTransaction> }

Represents a transaction that has been submitted to the blockchain but has not yet reached a final state. The PendingTransaction type extends certain functionalities from the base Transaction type, adding methods to monitor the transaction's progress towards being finalized (either included in a block or rejected).

Defined in

lib/mina/transaction.ts:130


PendingTransactionStatus

Ƭ PendingTransactionStatus: "pending" | "rejected"

Defined in

lib/mina/transaction.ts:124


RejectedTransaction

Ƭ RejectedTransaction: Pick\<PendingTransaction, "transaction" | "toJSON" | "toPretty" | "hash" | "data"> & { errors: string[] ; status: "rejected" }

Represents a transaction that has been rejected and not included in a blockchain block.

Defined in

lib/mina/transaction.ts:255


Transaction

Ƭ Transaction: Object

Defines the structure and operations associated with a transaction. This type encompasses methods for serializing the transaction, signing it, generating proofs, and submitting it to the network.

Type declaration

NameTypeDescription
transactionZkappCommandTransaction structure used to describe a state transition on the Mina blockchain.
prove() => Promise\<(undefined | Proof\<ZkappPublicInput, undefined>)[]>Initiates the proof generation process for the Transaction. This asynchronous operation is crucial for zero-knowledge-based transactions, where proofs are required to validate state transitions. This can take some time. Example ts await transaction.prove();
safeSend() => Promise\<PendingTransaction | RejectedTransaction>Sends the Transaction to the network. Unlike the standard send, this function does not throw an error if internal errors are detected. Instead, it returns a PendingTransaction if the transaction is successfully sent for processing or a RejectedTransaction if it encounters errors during processing or is outright rejected by the Mina daemon. Example ts const result = await transaction.safeSend(); if (result.status === 'pending') { console.log('Transaction sent successfully to the Mina daemon.'); } else if (result.status === 'rejected') { console.error('Transaction failed with errors:', result.errors); }
send() => Promise\<PendingTransaction>Submits the Transaction to the network. This method asynchronously sends the transaction for processing. If successful, it returns a PendingTransaction instance, which can be used to monitor the transaction's progress. If the transaction submission fails, this method throws an error that should be caught and handled appropriately. Throws An error if the transaction cannot be sent or processed by the network, containing details about the failure. Example ts try { const pendingTransaction = await transaction.send(); console.log('Transaction sent successfully to the Mina daemon.'); } catch (error) { console.error('Failed to send transaction to the Mina daemon:', error); }
sign(additionalKeys?: PrivateKey[]) => TransactionSigns all AccountUpdates included in the Transaction that require a signature. AccountUpdates that require a signature can be specified with {AccountUpdate\|SmartContract}.requireSignature(). Example ts const signedTx = transaction.sign([userPrivateKey]); console.log('Transaction signed successfully.');
toGraphqlQuery() => stringConstructs the GraphQL query string used for submitting the transaction to a Mina daemon.
toJSON() => stringSerializes the transaction to a JSON string.
toPretty() => anyProduces a pretty-printed JSON representation of the Transaction.

Defined in

lib/mina/transaction.ts:49

Variables

activeInstance

activeInstance: Mina

Defined in

lib/mina/mina-instance.ts:131

Functions

BerkeleyQANet

BerkeleyQANet(graphqlEndpoint): Mina

Parameters

NameType
graphqlEndpointstring

Returns

Mina

Deprecated

This is deprecated in favor of Network, which is exactly the same function. The name BerkeleyQANet was misleading because it suggested that this is specific to a particular network.

Defined in

lib/mina.ts:467


LocalBlockchain

LocalBlockchain(«destructured»?): Object

A mock Mina blockchain running locally and useful for testing.

Parameters

NameType
«destructured»Object
› enforceTransactionLimitsundefined | boolean
› networkIdundefined | NetworkId
› proofsEnabledundefined | boolean

Returns

Object

NameType
accountCreationFee() => UInt64
addAccount(publicKey: PublicKey, balance: string) => void
getNetworkId() => NetworkId
proofsEnabledboolean
testAccounts{ privateKey: PrivateKey ; publicKey: PublicKey }[]
applyJsonTransaction(json: string) => void
currentSlot() => UInt32
fetchActions(publicKey: PublicKey, actionStates?: ActionStates, tokenId: Field) => Promise\<{ actions: string[][] ; hash: string }[]>
fetchEvents(publicKey: PublicKey, tokenId: Field) => Promise\<any>
getAccount(publicKey: PublicKey, tokenId: Field) => Account
getActions(publicKey: PublicKey, actionStates?: ActionStates, tokenId: Field) => { actions: string[][] ; hash: string }[]
getNetworkConstants() => { accountCreationFee: UInt64 ; genesisTimestamp: UInt64 ; slotTime: UInt64 }
getNetworkState() => PreconditionBaseTypes\<{ blockchainLength: { isSome: Bool ; value: { lower: UInt32 ; upper: UInt32 } } ; globalSlotSinceGenesis: { isSome: Bool ; value: { lower: UInt32 ; upper: UInt32 } } ; minWindowDensity: { isSome: Bool ; value: { lower: UInt32 ; upper: UInt32 } } ; nextEpochData: { epochLength: { isSome: Bool ; value: { lower: UInt32 ; upper: UInt32 } } ; ledger: { hash: { isSome: Bool ; value: Field } ; totalCurrency: { isSome: Bool ; value: { lower: UInt64 ; upper: UInt64 } } } ; lockCheckpoint: { isSome: Bool ; value: Field } ; seed: { isSome: Bool ; value: Field } ; startCheckpoint: { isSome: Bool ; value: Field } } ; snarkedLedgerHash: { isSome: Bool ; value: Field } ; stakingEpochData: { epochLength: { isSome: Bool ; value: { lower: UInt32 ; upper: UInt32 } } ; ledger: { hash: { isSome: Bool ; value: Field } ; totalCurrency: { isSome: Bool ; value: { lower: UInt64 ; upper: UInt64 } } } ; lockCheckpoint: { isSome: Bool ; value: Field } ; seed: { isSome: Bool ; value: Field } ; startCheckpoint: { isSome: Bool ; value: Field } } ; totalCurrency: { isSome: Bool ; value: { lower: UInt64 ; upper: UInt64 } } }>
hasAccount(publicKey: PublicKey, tokenId: Field) => boolean
incrementGlobalSlot(increment: number | UInt32) => void
sendTransaction(txn: Transaction) => Promise\<PendingTransaction>
setBlockchainLength(height: UInt32) => void
setGlobalSlot(slot: number | UInt32) => void
setProofsEnabled(newProofsEnabled: boolean) => void
setTotalCurrency(currency: UInt64) => void
transaction(sender: DeprecatedFeePayerSpec, f: () => void) => Promise\<Transaction>

Defined in

lib/mina/local-blockchain.ts:45


Network

Network(graphqlEndpoint): Mina

Represents the Mina blockchain running on a real network

Parameters

NameType
graphqlEndpointstring

Returns

Mina

Defined in

lib/mina.ts:108

Network(options): Mina

Parameters

NameType
optionsObject
options.archive?string | string[]
options.lightnetAccountManager?string
options.minastring | string[]
options.networkId?NetworkId

Returns

Mina

Defined in

lib/mina.ts:109


accountCreationFee

accountCreationFee(): UInt64

Returns the default account creation fee.

Returns

UInt64

Deprecated

use getNetworkConstants

Defined in

lib/mina/mina-instance.ts:211


currentSlot

currentSlot(): UInt32

Returns

UInt32

The current slot number, according to the active Mina instance.

Defined in

lib/mina/mina-instance.ts:161


currentTransaction

currentTransaction(): undefined | CurrentTransaction

Returns

undefined | CurrentTransaction

Defined in

lib/global-context.ts:6


faucet

faucet(pub, network?): Promise\<void>

Requests the testnet faucet to fund a public key.

Parameters

NameTypeDefault value
pubPublicKeyundefined
networkstring'berkeley-qanet'

Returns

Promise\<void>

Defined in

lib/mina.ts:527


fetchActions

fetchActions(publicKey, actionStates?, tokenId?): Promise\<{ actions: string[][] ; hash: string }[] | { error: { statusCode: number = 404; statusText: string } }>

Parameters

NameType
publicKeyPublicKey
actionStates?ActionStates
tokenId?Field

Returns

Promise\<{ actions: string[][] ; hash: string }[] | { error: { statusCode: number = 404; statusText: string } }>

A list of emitted sequencing actions associated to the given public key.

Defined in

lib/mina/mina-instance.ts:229


fetchEvents

fetchEvents(publicKey, tokenId, filterOptions?): Promise\<{ blockHash: string = event.blockInfo.stateHash; blockHeight: UInt32 ; chainStatus: string = event.blockInfo.chainStatus; events: { data: string[] ; transactionInfo: { hash: string ; memo: string ; status: string } }[] ; globalSlot: UInt32 ; parentBlockHash: string = event.blockInfo.parentHash }[]>

Parameters

NameType
publicKeyPublicKey
tokenIdField
filterOptionsEventActionFilterOptions

Returns

Promise\<{ blockHash: string = event.blockInfo.stateHash; blockHeight: UInt32 ; chainStatus: string = event.blockInfo.chainStatus; events: { data: string[] ; transactionInfo: { hash: string ; memo: string ; status: string } }[] ; globalSlot: UInt32 ; parentBlockHash: string = event.blockInfo.parentHash }[]>

A list of emitted events associated to the given public key.

Defined in

lib/mina/mina-instance.ts:218


filterGroups

filterGroups(xs): Object

Parameters

NameType
xsAuthorizationKind[]

Returns

Object

NameType
proofnumber
signedPairnumber
signedSinglenumber

Defined in

lib/mina/transaction-validation.ts:130


getAccount

getAccount(publicKey, tokenId?): Account

Parameters

NameType
publicKeyPublicKey
tokenId?Field

Returns

Account

The account data associated to the given public key.

Defined in

lib/mina/mina-instance.ts:168


getActions

getActions(publicKey, actionStates?, tokenId?): { actions: string[][] ; hash: string }[]

Parameters

NameType
publicKeyPublicKey
actionStates?ActionStates
tokenId?Field

Returns

{ actions: string[][] ; hash: string }[]

A list of emitted sequencing actions associated to the given public key.

Defined in

lib/mina/mina-instance.ts:240


getBalance

getBalance(publicKey, tokenId?): UInt64

Parameters

NameType
publicKeyPublicKey
tokenId?Field

Returns

UInt64

The balance associated to the given public key.

Defined in

lib/mina/mina-instance.ts:203


getNetworkConstants

getNetworkConstants(): NetworkConstants

Returns

NetworkConstants

Data associated with the current Mina network constants.

Defined in

lib/mina/mina-instance.ts:189


getNetworkId

getNetworkId(): NetworkId

Returns

NetworkId

The current Mina network ID.

Defined in

lib/mina/mina-instance.ts:182


getNetworkState

getNetworkState(): PreconditionBaseTypes\<{ blockchainLength: { isSome: Bool ; value: { lower: UInt32 ; upper: UInt32 } } ; globalSlotSinceGenesis: { isSome: Bool ; value: { lower: UInt32 ; upper: UInt32 } } ; minWindowDensity: { isSome: Bool ; value: { lower: UInt32 ; upper: UInt32 } } ; nextEpochData: { epochLength: { isSome: Bool ; value: { lower: UInt32 ; upper: UInt32 } } ; ledger: { hash: { isSome: Bool ; value: Field } ; totalCurrency: { isSome: Bool ; value: { lower: UInt64 ; upper: UInt64 } } } ; lockCheckpoint: { isSome: Bool ; value: Field } ; seed: { isSome: Bool ; value: Field } ; startCheckpoint: { isSome: Bool ; value: Field } } ; snarkedLedgerHash: { isSome: Bool ; value: Field } ; stakingEpochData: { epochLength: { isSome: Bool ; value: { lower: UInt32 ; upper: UInt32 } } ; ledger: { hash: { isSome: Bool ; value: Field } ; totalCurrency: { isSome: Bool ; value: { lower: UInt64 ; upper: UInt64 } } } ; lockCheckpoint: { isSome: Bool ; value: Field } ; seed: { isSome: Bool ; value: Field } ; startCheckpoint: { isSome: Bool ; value: Field } } ; totalCurrency: { isSome: Bool ; value: { lower: UInt64 ; upper: UInt64 } } }>

Returns

PreconditionBaseTypes\<{ blockchainLength: { isSome: Bool ; value: { lower: UInt32 ; upper: UInt32 } } ; globalSlotSinceGenesis: { isSome: Bool ; value: { lower: UInt32 ; upper: UInt32 } } ; minWindowDensity: { isSome: Bool ; value: { lower: UInt32 ; upper: UInt32 } } ; nextEpochData: { epochLength: { isSome: Bool ; value: { lower: UInt32 ; upper: UInt32 } } ; ledger: { hash: { isSome: Bool ; value: Field } ; totalCurrency: { isSome: Bool ; value: { lower: UInt64 ; upper: UInt64 } } } ; lockCheckpoint: { isSome: Bool ; value: Field } ; seed: { isSome: Bool ; value: Field } ; startCheckpoint: { isSome: Bool ; value: Field } } ; snarkedLedgerHash: { isSome: Bool ; value: Field } ; stakingEpochData: { epochLength: { isSome: Bool ; value: { lower: UInt32 ; upper: UInt32 } } ; ledger: { hash: { isSome: Bool ; value: Field } ; totalCurrency: { isSome: Bool ; value: { lower: UInt64 ; upper: UInt64 } } } ; lockCheckpoint: { isSome: Bool ; value: Field } ; seed: { isSome: Bool ; value: Field } ; startCheckpoint: { isSome: Bool ; value: Field } } ; totalCurrency: { isSome: Bool ; value: { lower: UInt64 ; upper: UInt64 } } }>

Data associated with the current state of the Mina network.

Defined in

lib/mina/mina-instance.ts:196


getProofsEnabled

getProofsEnabled(): boolean

Returns

boolean

Defined in

lib/mina/mina-instance.ts:248


hasAccount

hasAccount(publicKey, tokenId?): boolean

Checks if an account exists within the ledger.

Parameters

NameType
publicKeyPublicKey
tokenId?Field

Returns

boolean

Defined in

lib/mina/mina-instance.ts:175


sender

sender(): PublicKey

Returns the public key of the current transaction's sender account.

Throws an error if not inside a transaction, or the sender wasn't passed in.

Returns

PublicKey

Defined in

lib/mina.ts:476


setActiveInstance

setActiveInstance(m): void

Set the currently used Mina instance.

Parameters

NameType
mMina

Returns

void

Defined in

lib/mina/mina-instance.ts:150


transaction

transaction(sender, f): Promise\<Transaction>

Construct a smart contract transaction. Within the callback passed to this function, you can call into the methods of smart contracts.

let tx = await Mina.transaction(sender, () => {
myZkapp.update();
someOtherZkapp.someOtherMethod();
});

Parameters

NameType
senderFeePayerSpec
f() => void

Returns

Promise\<Transaction>

A transaction that can subsequently be submitted to the chain.

Defined in

lib/mina/transaction.ts:468

transaction(f): Promise\<Transaction>

Parameters

NameType
f() => void

Returns

Promise\<Transaction>

Defined in

lib/mina/transaction.ts:469

transaction(sender, f): Promise\<Transaction>

Parameters

NameType
senderDeprecatedFeePayerSpec
f() => void

Returns

Promise\<Transaction>

Deprecated

It's deprecated to pass in the fee payer's private key. Pass in the public key instead.

// good
Mina.transaction(publicKey, ...);
Mina.transaction({ sender: publicKey }, ...);

// deprecated
Mina.transaction(privateKey, ...);
Mina.transaction({ feePayerKey: privateKey }, ...);

Defined in

lib/mina/transaction.ts:482


waitForFunding

waitForFunding(address): Promise\<void>

Parameters

NameType
addressstring

Returns

Promise\<void>

Defined in

lib/mina.ts:503