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
:
Parameter | Required | Description |
---|---|---|
chainId | true | The chain ID of the asset. |
assetSymbol | true | The asset symbol. |
version | false | The version of the spend. |
amount | false | The amount of the spend. |
useRelayer | false | Whether to use a relayer. |
queryTimeoutMs | false | The query timeout in milliseconds. |
spendType | false | The type of spend. |
bridgeType | false | The bridge type. |
SpendQuote
data structure is as follows:
Property | Type | Description |
---|---|---|
valid | boolean | Whether the quote is valid. |
assetSymbol | string | The asset symbol. |
assetDecimals | number | The asset decimals. |
currentBalance | number | The current balance. |
currentDecimalBalance | string | The current decimal balance. |
numOfInputs | bigint | The number of inputs. |
numOfOutputs | bigint | The number of outputs. |
minRollupFee | number | The minimum rollup fee. |
minRollupFeeDecimal | string | The minimum rollup fee decimal. |
rollupFeeAssetSymbol | string | The rollup fee asset symbol. |
rollupFeeAssetDecimals | number | The rollup fee asset decimals. |
fixedAmounts | number[] | The fixed amounts. |
fixedDecimalAmounts | string[] | The fixed decimal amounts. |
selectedCommitments | string[] | The selected commitments. |
gasRelayers | GasRelayer[] | The gas relayers. |
maxGasRelayerFee | number | The maximum gas relayer fee. |
maxGasRelayerFeeDecimal | string | The maximum gas relayer fee decimal. |
gasRelayerFeeAssetSymbol | string | The gas relayer fee asset symbol. |
gasRelayerFeeAssetDecimals | number | The gas relayer fee asset decimals. |
invalidCode | SpendInvalidCode | The invalid code. |
amountRange | AmountRange | 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
:
Parameter | Required | Description |
---|---|---|
chainId | true | The chain ID of the asset. |
assetSymbol | true | The asset symbol. |
amount | true | The amount of the spend. |
recipient | true | The recipient address. |
walletPassword | true | The wallet password. |
version | false | The version of the spend. |
rollupFeeAmount | false | The rollup fee amount. |
gasRelayer | false | The gas relayer. |
queryTimeoutMs | false | The query timeout in milliseconds. |
spendQuote | false | The spend quote. |
spendType | false | The type of spend. |
bridgeType | false | The bridge type. |
SpendSummary
data structure is as follows:
Property | Type | Description |
---|---|---|
assetSymbol | string | The asset symbol. |
assetDecimals | number | The asset decimals. |
currentBalance | number | The current balance. |
currentDecimalBalance | string | The current decimal balance. |
newBalance | number | The new balance. |
newDecimalBalance | string | The new decimal balance. |
amount | number | The amount. |
decimalAmount | string | The decimal amount. |
recipient | string | The recipient address. |
rollupFeeAmount | number | The rollup fee amount. |
rollupFeeDecimalAmount | string | The rollup fee decimal amount. |
rollupFeeTotalAmount | number | The rollup fee total amount. |
rollupFeeTotalDecimalAmount | string | The rollup fee total decimal amount. |
rollupFeeAssetSymbol | string | The rollup fee asset symbol. |
rollupFeeAssetDecimals | number | The rollup fee asset decimals. |
gasRelayerFeeAmount | number | The gas relayer fee amount. |
gasRelayerFeeDecimalAmount | string | The gas relayer fee decimal amount. |
gasRelayerFeeAssetSymbol | string | The gas relayer fee asset symbol. |
gasRelayerFeeAssetDecimals | number | The gas relayer fee asset decimals. |
gasRelayerAddress | string | The gas relayer address. |
gasRelayerName | string | The gas relayer name. |
gasRelayerUrl | string | 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:
Property | Type | Description |
---|---|---|
id | string | The ID of the spend. |
createdAt | bigint | The creation time of the spend. |
updatedAt | bigint | The update time of the spend. |
chainId | bigint | The chain ID of the asset. |
contractAddress | string | The contract address. |
assetSymbol | string | The asset symbol. |
assetDecimals | number | The asset decimals. |
amount | number | The amount. |
decimalAmount | string | The decimal amount. |
recipient | string | The recipient address. |
walletId | string | The wallet ID. |
inputCommitments | string[] | The input commitments. |
outputCommitments | string[] | The output commitments. |
nullifiers | string[] | The nullifiers. |
signaturePublicKeyHashes | string[] | The signature public key hashes. |
encryptedAuditorNotes | string[] | The encrypted auditor notes. |
rollupFeeAmount | number | The rollup fee amount. |
rollupFeeDecimalAmount | string | The rollup fee decimal amount. |
rollupFeeTotalAmount | number | The rollup fee total amount. |
rollupFeeTotalDecimalAmount | string | The rollup fee total decimal amount. |
gasRelayerFeeAmount | number | The gas relayer fee amount. |
gasRelayerFeeDecimalAmount | string | The gas relayer fee decimal amount. |
signaturePublicKey | string | The signature public key. |
assetAddress | string | The asset address. |
proof | string | The proof. |
rootHash | string | The root hash. |
gasRelayerAddress | string | The gas relayer address. |
gasRelayerUrl | string | The gas relayer URL. |
signature | string | The signature. |
randomAuditingPublicKey | string | The random auditing public key. |
errorMessage | string | The error message. |
transactionHash | string | The transaction hash. |
bridgeType | BridgeType | The bridge type. |
spendType | SpendType | The spend type. |
status | SpendStatus | 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
:
Parameter | Required | Description |
---|---|---|
spendId | true | The ID of the spend. |
walletPassword | true | The wallet password. |
privateKey | false | The private key. |
signerProvider | false | The signer provider. |
queryTimeoutMs | false | The query timeout in milliseconds. |
spendConfirmations | false | The spend confirmations. |
txSendTimeoutMs | false | The transaction send timeout in milliseconds. |
txWaitTimeoutMs | false | The transaction wait timeout in milliseconds. |
txWaitIntervalMs | false | The transaction wait interval in milliseconds. |
relayerWaitTimeoutMs | false | The relayer wait timeout in milliseconds. |
relayerWaitIntervalMs | false | The relayer wait interval in milliseconds. |
tx | false | The transaction. |
rawMerkleTree | false | The raw Merkle tree. |
rawZkProgram | false | The raw ZK program. |
rawZkProvingKey | false | The raw ZK proving key. |
rawZkVerifyingKey | false | The raw ZK verifying key. |
rawZkAbi | false | 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
:
Parameter | Required | Description |
---|---|---|
host | true | Host. |
port | true | Port. |
isSsl | false | Is SSL. |
sslCert | false | SSL cert. |
sslCertPath | false | SSL cert path. |
sslServerName | false | 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();