Skip to main content

Spend

Mystiko Spend Related APIs.

Data Structures

Quote

Retrieve quote information for a spend.

import mystiko from '@mystikonetwork/node';
import { core, common } from '@mystikonetwork/protos';

const options = new core.handler.v1.QuoteSpendOptions({
chainId: BigInt(11155111),
assetSymbol: 'MTT',
bridgeType: common.v1.BridgeType.TBRIDGE,
});
const spendQuote = mystiko.spend?.quote(options);

QuoteSpendOptions:

ParameterRequiredDescription
chainIdtrue
The chain ID of the asset.
assetSymboltrue
The asset symbol.
versionfalse
The version of the spend.
amountfalse
The amount of the spend.
useRelayerfalse
Whether to use a relayer.
queryTimeoutMsfalse
The query timeout in milliseconds.
spendTypefalse
The type of spend.
bridgeTypefalse
The bridge type.

SpendQuote data structure is as follows:

PropertyTypeDescription
validboolean
Whether the quote is valid.
assetSymbolstring
The asset symbol.
assetDecimalsnumber
The asset decimals.
currentBalancenumber
The current balance.
currentDecimalBalancestring
The current decimal balance.
numOfInputsbigint
The number of inputs.
numOfOutputsbigint
The number of outputs.
minRollupFeenumber
The minimum rollup fee.
minRollupFeeDecimalstring
The minimum rollup fee decimal.
rollupFeeAssetSymbolstring
The rollup fee asset symbol.
rollupFeeAssetDecimalsnumber
The rollup fee asset decimals.
fixedAmountsnumber[]
The fixed amounts.
fixedDecimalAmountsstring[]
The fixed decimal amounts.
selectedCommitmentsstring[]
The selected commitments.
gasRelayersGasRelayer[]
The gas relayers.
maxGasRelayerFeenumber
The maximum gas relayer fee.
maxGasRelayerFeeDecimalstring
The maximum gas relayer fee decimal.
gasRelayerFeeAssetSymbolstring
The gas relayer fee asset symbol.
gasRelayerFeeAssetDecimalsnumber
The gas relayer fee asset decimals.
invalidCodeSpendInvalidCode
The invalid code.
amountRangeAmountRange
The amount range.

Summary

Retrieve summary information for a spend.

import mystiko from '@mystikonetwork/node';
import { core, common } from '@mystikonetwork/protos';

const options = new core.handler.v1.CreateSpendOptions({
chainId: BigInt(11155111),
assetSymbol: 'MTT',
amount: 1,
spendType: core.v1.SpendType.WITHDRAW,
bridgeType: common.v1.BridgeType.TBRIDGE,
});

const spendSummary = mystiko.spend?.summary(options);

CreateSpendOptions:

ParameterRequiredDescription
chainIdtrue
The chain ID of the asset.
assetSymboltrue
The asset symbol.
amounttrue
The amount of the spend.
recipienttrue
The recipient address.
walletPasswordtrue
The wallet password.
versionfalse
The version of the spend.
rollupFeeAmountfalse
The rollup fee amount.
gasRelayerfalse
The gas relayer.
queryTimeoutMsfalse
The query timeout in milliseconds.
spendQuotefalse
The spend quote.
spendTypefalse
The type of spend.
bridgeTypefalse
The bridge type.

SpendSummary data structure is as follows:

PropertyTypeDescription
assetSymbolstring
The asset symbol.
assetDecimalsnumber
The asset decimals.
currentBalancenumber
The current balance.
currentDecimalBalancestring
The current decimal balance.
newBalancenumber
The new balance.
newDecimalBalancestring
The new decimal balance.
amountnumber
The amount.
decimalAmountstring
The decimal amount.
recipientstring
The recipient address.
rollupFeeAmountnumber
The rollup fee amount.
rollupFeeDecimalAmountstring
The rollup fee decimal amount.
rollupFeeTotalAmountnumber
The rollup fee total amount.
rollupFeeTotalDecimalAmountstring
The rollup fee total decimal amount.
rollupFeeAssetSymbolstring
The rollup fee asset symbol.
rollupFeeAssetDecimalsnumber
The rollup fee asset decimals.
gasRelayerFeeAmountnumber
The gas relayer fee amount.
gasRelayerFeeDecimalAmountstring
The gas relayer fee decimal amount.
gasRelayerFeeAssetSymbolstring
The gas relayer fee asset symbol.
gasRelayerFeeAssetDecimalsnumber
The gas relayer fee asset decimals.
gasRelayerAddressstring
The gas relayer address.
gasRelayerNamestring
The gas relayer name.
gasRelayerUrlstring
The gas relayer URL.

Create

Create a Spend request.

import mystiko from '@mystikonetwork/node';
import { core } from '@mystikonetwork/protos';

const options = new core.handler.v1.CreateSpendOptions({
chainId: BigInt(11155111),
assetSymbol: 'MTT',
amount: 1,
bridgeType: common.v1.BridgeType.TBRIDGE,
walletPassword: 'walletPassword',
});
const spend = mystiko.spend?.create(options);

Spend data structure is as follows:

PropertyTypeDescription
idstring
The ID of the spend.
createdAtbigint
The creation time of the spend.
updatedAtbigint
The update time of the spend.
chainIdbigint
The chain ID of the asset.
contractAddressstring
The contract address.
assetSymbolstring
The asset symbol.
assetDecimalsnumber
The asset decimals.
amountnumber
The amount.
decimalAmountstring
The decimal amount.
recipientstring
The recipient address.
walletIdstring
The wallet ID.
inputCommitmentsstring[]
The input commitments.
outputCommitmentsstring[]
The output commitments.
nullifiersstring[]
The nullifiers.
signaturePublicKeyHashesstring[]
The signature public key hashes.
encryptedAuditorNotesstring[]
The encrypted auditor notes.
rollupFeeAmountnumber
The rollup fee amount.
rollupFeeDecimalAmountstring
The rollup fee decimal amount.
rollupFeeTotalAmountnumber
The rollup fee total amount.
rollupFeeTotalDecimalAmountstring
The rollup fee total decimal amount.
gasRelayerFeeAmountnumber
The gas relayer fee amount.
gasRelayerFeeDecimalAmountstring
The gas relayer fee decimal amount.
signaturePublicKeystring
The signature public key.
assetAddressstring
The asset address.
proofstring
The proof.
rootHashstring
The root hash.
gasRelayerAddressstring
The gas relayer address.
gasRelayerUrlstring
The gas relayer URL.
signaturestring
The signature.
randomAuditingPublicKeystring
The random auditing public key.
errorMessagestring
The error message.
transactionHashstring
The transaction hash.
bridgeTypeBridgeType
The bridge type.
spendTypeSpendType
The spend type.
statusSpendStatus
The spend status.

Send

Send a spend transaction using a private key.

import mystiko from '@mystikonetwork/node';
import { core } from '@mystikonetwork/protos';

const options = new core.handler.v1.SendSpendOptions({
spendId: 'id',
walletPassword: 'walletPassword',
privateKey: 'private key of transaction signer'
});
const spend = mystiko.spend?.send(options);

SendSpendOptions:

ParameterRequiredDescription
spendIdtrue
The ID of the spend.
walletPasswordtrue
The wallet password.
privateKeyfalse
The private key.
signerProviderfalse
The signer provider.
queryTimeoutMsfalse
The query timeout in milliseconds.
spendConfirmationsfalse
The spend confirmations.
txSendTimeoutMsfalse
The transaction send timeout in milliseconds.
txWaitTimeoutMsfalse
The transaction wait timeout in milliseconds.
txWaitIntervalMsfalse
The transaction wait interval in milliseconds.
relayerWaitTimeoutMsfalse
The relayer wait timeout in milliseconds.
relayerWaitIntervalMsfalse
The relayer wait interval in milliseconds.
txfalse
The transaction.
rawMerkleTreefalse
The raw Merkle tree.
rawZkProgramfalse
The raw ZK program.
rawZkProvingKeyfalse
The raw ZK proving key.
rawZkVerifyingKeyfalse
The raw ZK verifying key.
rawZkAbifalse
The raw ZK ABI.

SendWithGrpc

Send a spend transaction by signing through the given gRPC interface.

import mystiko from '@mystikonetwork/node';
import { core, service } from '@mystikonetwork/protos';

const options1 = new core.handler.v1.SendSpendOptions({
spendId: 'id',
walletPassword: 'walletPassword'
});
const options2 = new service.v1.ClientOptions({});
const spend = mystiko.spend?.sendWithGrpc(options1, options2);

ClientOptions:

ParameterRequiredDescription
hosttrue
Host.
porttrue
Port.
isSslfalse
Is SSL.
sslCertfalse
SSL cert.
sslCertPathfalse
SSL cert path.
sslServerNamefalse
SSL server name.

Find

Query Spend data using Filter.

import mystiko from '@mystikonetwork/node';
import { storage } from '@mystikonetwork/protos';

const filter = new storage.v1.SubFilter({
column: 'id',
values: ['id'],
operator: storage.v1.SubFilterOperator.IN,
});
const spends = mystiko.spend?.find(filter);

FindAll

Query all Spend data.

import mystiko from '@mystikonetwork/node';

const spends = mystiko.spend?.find(undefined);

FindOne

Find a single Spend record using Filter.

import mystiko from '@mystikonetwork/node';
import { storage } from '@mystikonetwork/protos';

const filter = new storage.v1.SubFilter({
column: 'id',
values: ['id'],
operator: storage.v1.SubFilterOperator.IN,
});
const spend = mystiko.spend?.findOne(filter);

FindById

Find a single Spend record by its ID.

import mystiko from '@mystikonetwork/node';

const spend = mystiko.spend?.findById('id');

Count

Query the count of data that matches the Filter criteria.

import mystiko from '@mystikonetwork/node';
import { storage } from '@mystikonetwork/protos';

const filter = new storage.v1.SubFilter({
column: 'id',
values: ['id'],
operator: storage.v1.SubFilterOperator.IN,
});
const total = mystiko.spend?.count(filter);

CountAll

Query the total count of all Spend data.

import mystiko from '@mystikonetwork/node';

const total = mystiko.spend?.count(undefined);

Update

Update a Spend record.

import mystiko from '@mystikonetwork/node';

const spend = mystiko.spend?.findById('id');
spend.amount = 2000;
const updatedSpend = mystiko.spend?.update(spend);

UpdateBatch

Batch update Spend records.

import mystiko from '@mystikonetwork/node';

const spend = mystiko.spend?.findById("id");
spend.amount = 2000;
const newSpends = mystiko.spend?.updateBatch([spend]);

UpdateByFilter

Update Spend records based on the conditions specified in the Filter.

import mystiko from '@mystikonetwork/node';
import { api, storage } from '@mystikonetwork/protos';

const columnValues = [
new api.handler.v1.ColumnValuePair({
column: 'amount',
value: new storage.v1.ColumnValue({
value: {
value: 2000,
case: 'f64Value',
},
}),
}),
];
const filter = new storage.v1.QueryFilter({
conditions: [],
conditionsOperator: storage.v1.ConditionOperator.OR,
});
mystiko.spend?.updateByValues(columnValues, filter);

UpdateAll

Update all Spend records.

import mystiko from '@mystikonetwork/node';
import { api, storage } from '@mystikonetwork/protos';

const columnValues = [
new api.handler.v1.ColumnValuePair({
column: 'amount',
value: new storage.v1.ColumnValue({
value: {
value: 2000,
case: 'f64Value',
},
}),
}),
];
mystiko.spend?.updateByValues(columnValues, undefined);

Delete

Delete a Spend record.

import mystiko from '@mystikonetwork/node';

const spend = mystiko.spend?.findById("id");
mystiko.spend?.delete(spend);

DeleteBatch

Batch delete Spend records.

import mystiko from '@mystikonetwork/node';

const spend = mystiko.spend?.findById("id");
mystiko.spend?.deleteBatch(spend);

DeleteByFilter

Delete Spend records based on the conditions specified in the Filter.

import mystiko from '@mystikonetwork/node';
import { storage } from '@mystikonetwork/protos';

const filter = new storage.v1.SubFilter({
column: 'id',
values: ['id'],
operator: storage.v1.SubFilterOperator.IN,
});
const total = mystiko.spend?.deleteByFilter(filter);

DeleteAll

Delete all Spend records.

import mystiko from '@mystikonetwork/node';

mystiko.spend?.deleteAll();