Your local node is a small Qubic chain of your own. A tick is one block, and an epoch is a longer period (about a week on mainnet). Contracts can run code on these boundaries. Locally you can skip ahead instead of waiting.
Example contract
qinit new Clock, then replace contracts/Clock.h:
using namespace QPI;
struct Clock2 {};
struct Clock : public ContractBase
{
struct StateData
{
uint32 epochsSeen;
uint16 lastEpoch;
uint32 lastTick;
};
struct Now_input {};
struct Now_output { uint32 epochsSeen; uint16 lastEpoch; uint32 lastTick; };
// runs once at the start of every epoch
BEGIN_EPOCH()
{
state.mut().epochsSeen += 1;
state.mut().lastEpoch = qpi.epoch();
}
// runs after every tick
END_TICK()
{
state.mut().lastTick = qpi.tick();
}
PUBLIC_FUNCTION(Now)
{
output.epochsSeen = state.get().epochsSeen;
output.lastEpoch = state.get().lastEpoch;
output.lastTick = state.get().lastTick;
}
REGISTER_USER_FUNCTIONS_AND_PROCEDURES()
{
REGISTER_USER_FUNCTION(Now, 1);
}
};Skip time
qinit deploy
qinit tickepoch 1
tick 2866
epoch last tick 5401
ticks left 2535
epoch length 2701 ticks$ qinit tick advance 100tick 2866 → 2966
advanced 100$ qinit epoch advanceepoch 1 → 2
tick 2967 → 5403
new epoch start tick 5403$ qinit call --fn Clock Now✓ Clock.Now
out {epochsSeen: 1, lastEpoch: 2, lastTick: 5405}qinit tick(orqinit epoch) shows the current tick, epoch, and ticks left in the epoch.tick advance <n>runsnticks right away.tick advance-to-lastjumps to just before the epoch ends, so you can test end-of-epoch logic.epoch advancefinishes the current epoch, soEND_EPOCHand thenBEGIN_EPOCHrun.tick rate 500slows ticking to 500 ms per tick.tick rate 100makes it fast again.
Node options
qinit node run --tick-ms 100
qinit node run --fees off
qinit node run --restart
qinit node stop--tick-mssets the tick speed when the node starts (simulator).--fees offturns off execution fees (simulator). By default each contract pays for its CPU time out of a fee reserve. A contract whose reserve runs out goes dormant: its procedures stop running, but its functions still answer.--restartstarts a fresh chain even if a node is already running.--keepkeeps the existing chain data instead.
System contracts
System contracts are the contracts already live on mainnet: QX, QUTIL, QEARN, and the rest. Their code ships inside the node, and each one sits at its mainnet slot. On the simulator they are loaded only when you ask for them:
$ qinit system lsslot contract state (add: qinit system add <name…>)
• 1 QX available
• 2 QTRY available
• 3 RANDOM available
• 4 QUTIL available
…$ qinit system add QX✓ QX @ 1 deployed · contracts/system_scs/Qx.h
✓ qinit.json system += QX$ qinit system rm QX✓ QX @ 1 removedadd deploys the contract at its mainnet slot, along with any contracts it depends on, and records the choice in qinit.json so the next simulator start loads it again. rm refuses while a deployed contract still calls it. Pass --force to remove it anyway. On the core runtime, system contracts are always built in.
Upgrade and move state
Redeploying keeps a contract's state. Changing StateData, saving state to a file, and starting a contract from one are covered in Migrate state.