How to migrate from Mystique API to TzKT Tezos Explorer API

Guide on How to migrate from Mystique (mimics the TzScan API) to TzKT Tezos Explorer API

Dmitry
Dmitry   Follow

Last year we released Mystique API that mimics the TzScan API, which suddenly died, so we really needed a workaround while our TzKT Tezos API was under development. Now that it’s done, we’ll describe how to painlessly migrate from mystique.tzkt.io to api.tzkt.io, a more stable and much faster Tezos API.

In this guide, we will describe all Mystique API endpoints, used for the last month. If you need some endpoints, missed in this guide, just contact us and we’ll add them to the migration guide.

Keep in mind, it’s just another TzScan mimic guide which helps you migrate from Mystique API. TzKT Tezos API, for sure, will work better, than Mystique API (a workaround, as described before), but it’s not necessary to use it exactly this way. TzKT API itself provides much more detailed and accurate data so you can create more complex apps and services. Don’t limit yourself to the outdated TzScan format.

WARNING

Mystique API will be shut down in the end of July

# Staking rewards split

/rewards_split/{address}?cycle={cycle} 🡒 /rewards/split/{address}/{cycle}

var tzkt_reward = get('/rewards/split/{address}/{cycle}');

var mystique_reward = {
  delegate_staking_balance:                    tzkt_reward.stakingBalance, //long
  delegators_nb:                               tzkt_reward.numDelegators, //int
  blocks_rewards:                              tzkt_reward.ownBlockRewards
                                             + tzkt_reward.extraBlockRewards, //long
  endorsements_rewards:                        tzkt_reward.endorsementRewards, //long
  fees:                                        tzkt_reward.ownBlockFees
                                             + tzkt_reward.extraBlockFees, //long
  future_blocks_rewards:                       tzkt_reward.futureBlockRewards, //long
  future_endorsements_rewards:                 tzkt_reward.futureEndorsementRewards, //long

  gain_from_denounciation_baking:              tzkt_reward.doubleBakingRewards, //long
  lost_deposit_from_denounciation_baking:      tzkt_reward.doubleBakingLostDeposits, //long
  lost_rewards_denounciation_baking:           tzkt_reward.doubleBakingLostRewards, //long
  lost_fees_denounciation_baking:              tzkt_reward.doubleBakingLostFees, //long

  gain_from_denounciation_endorsement:         tzkt_reward.doubleEndorsingRewards, //long
  lost_deposit_from_denounciation_endorsement: tzkt_reward.doubleEndorsingLostDeposits, //long
  lost_rewards_denounciation_endorsement:      tzkt_reward.doubleEndorsingLostRewards, //long
  lost_fees_denounciation_endorsement:         tzkt_reward.doubleEndorsingLostFees, //long

  revelation_rewards:                          tzkt_reward.revelationRewards, //long
  lost_revelation_rewards:                     tzkt_reward.revelationLostRewards, //long
  lost_revelation_fees:                        tzkt_reward.revelationLostFees, //long

  delegators_balance: tzkt_reward.delegators.map(v => ({
    account: {
      tz: v.address
    },
    balance: v.balance
  }))
}

# Staking rewards split cycles

/rewards_split_cycles/{address} 🡒 /rewards/bakers/{address}

var tzkt_reward = get('/rewards/bakers/{address}')[0];
var current_cycle = (get('/head').level - 1) / 4096;

var mystique_reward = {
  cycle:                                  tzkt_reward.cycle, // int
  delegate_staking_balance:               tzkt_reward.stakingBalance, //long
  delegators_nb:                          tzkt_reward.numDelegators, //int
  delegated_balance:                      tzkt_reward.delegatedBalance, //long
  blocks_rewards:                         tzkt_reward.ownBlockRewards
                                        + tzkt_reward.extraBlockRewards, //long
  endorsements_rewards:                   tzkt_reward.endorsementRewards, //long
  fees:                                   tzkt_reward.ownBlockFees  
                                        + tzkt_reward.extraBlockFees, //long
  future_baking_rewards:                  tzkt_reward.futureBlockRewards, //long
  future_endorsing_rewards:               tzkt_reward.futureEndorsementRewards, //long
  revelation_rewards:                     tzkt_reward.revelationRewards, //long
  baking_denounciation_gain:              tzkt_reward.doubleBakingRewards, //long
  endorsement_denounciation_gain:         tzkt_reward.doubleEndorsingRewards, //long
  revelation_lost_rewards:                tzkt_reward.revelationLostRewards, //long
  revelation_lost_fees:                   tzkt_reward.revelationLostFees, //long
  baking_denounciation_lost_deposit:      tzkt_reward.doubleBakingLostDeposits, //long
  baking_denounciation_lost_rewards:      tzkt_reward.doubleBakingLostRewards, //long
  baking_denounciation_lost_fees:         tzkt_reward.doubleBakingLostFees, //long
  endorsement_denounciation_lost_deposit: tzkt_reward.doubleEndorsingLostDeposits, //long
  endorsement_denounciation_lost_rewards: tzkt_reward.doubleEndorsingLostRewards, //long
  endorsement_denounciation_lost_fees:    tzkt_reward.doubleEndorsingLostFees, //long
  status: {
    status: tzkt_reward.cycle <   current_cycle - 5 ? "rewards_delivered" :
            tzkt_reward.cycle <   current_cycle     ? "rewards_pending"   :
            tzkt_reward.cycle === current_cycle     ? "cycle_in_progress" :
                                                       "cycle_pending"
  } //string
}

# Snapshot levels

/snapshot_levels 🡒 /cycles?select=snapshotLevel

# Tezos delegator rewards with details

/delegator_rewards_with_details/{address} 🡒 /rewards/delegators/{address}

var tzkt_reward = get('/rewards/delegators/{address}')[0];
var current_cycle = (get('/head').level - 1) / 4096;

var mystique_reward = {
  cycle:                                  tzkt_reward.cycle, // int
  staking_balance:                        tzkt_reward.stakingBalance, //long
  balance:                                tzkt_reward.balance, //int
  rewards:                                tzkt_reward.ownBlockRewards 
                                        + tzkt_reward.extraBlockRewards 
                                        + tzkt_reward.futureBlockRewards 
                                        + tzkt_reward.endorsementRewards  
                                        + tzkt_reward.futureEndorsementRewards  
                                        + tzkt_reward.ownBlockFees  
                                        + tzkt_reward.extraBlockFees, //long
  extra_rewards:                          tzkt_reward.revelationRewards 
                                        + tzkt_reward.doubleBakingRewards 
                                        + tzkt_reward.doubleEndorsingRewards , //long
  losses:                                 tzkt_reward.revelationLostRewards 
                                        + tzkt_reward.revelationLostFees  
                                        + tzkt_reward.doubleBakingLostDeposits  
                                        + tzkt_reward.doubleBakingLostRewards  
                                        + tzkt_reward.doubleBakingLostFees   
                                        + tzkt_reward.doubleEndorsingLostDeposits   
                                        + tzkt_reward.doubleEndorsingLostRewards   
                                        + tzkt_reward.doubleEndorsingLostFees, //long
  block_rewards:                          tzkt_reward.ownBlockRewards   
                                        + tzkt_reward.extraBlockRewards 
                                        + tzkt_reward.futureBlockRewards , //long
  endorsement_rewards:                    tzkt_reward.endorsementRewards 
                                        + tzkt_reward.futureEndorsementRewards, //long
  fees:                                   tzkt_reward.ownBlockFees 
                                        + tzkt_reward.extraBlockFees, //long
  revelation_rewards:                     tzkt_reward.revelationRewards, //long
  baking_denounciation_gain:              tzkt_reward.doubleBakingRewards, //long
  endorsement_denounciation_gain:         tzkt_reward.doubleEndorsingRewards, //long
  revelation_lost_rewards:                tzkt_reward.revelationLostRewards, //long
  revelation_lost_fees:                   tzkt_reward.revelationLostFees, //long
  baking_denounciation_lost_deposit:      tzkt_reward.doubleBakingLostDeposits, //long
  baking_denounciation_lost_rewards:      tzkt_reward.doubleBakingLostRewards, //long
  baking_denounciation_lost_fees:         tzkt_reward.doubleBakingLostFees, //long
  endorsement_denounciation_lost_deposit: tzkt_reward.doubleEndorsingLostDeposits, //long
  endorsement_denounciation_lost_rewards: tzkt_reward.doubleEndorsingLostRewards, //long
  endorsement_denounciation_lost_fees:    tzkt_reward.doubleEndorsingLostFees, //long
  delegate: {
    tz:                                   tzkt_reward.baker.address //string
  },
  status: {
    status: tzkt_reward.cycle <   current_cycle - 5 ? "rewards_delivered" :
            tzkt_reward.cycle <   current_cycle     ? "rewards_pending"   :
            tzkt_reward.cycle === current_cycle     ? "cycle_in_progress" :
                                                      "cycle_pending"  //string
  }
}

# Number operations

/number_operations/{address} 🡒 /accounts/{address}

var tzkt_account = get('/accounts/{address}');
var mystique_op_number = [ tzkt_account.numTransactions ];

# Operations

/operations/{address} 🡒 /accounts/{address}/operations

var tzkt_operation = get('/accounts/{address}/operations?type=transaction')[0];

var mystique_operation = {
    hash:                  tzkt_operation.hash, //string
    block_hash:            tzkt_operation.block, //string
    type: {
        kind:              "manager",
        source: {
            tz:            tzkt_operation.sender.address //string
        },
        operations: {
            kind:          tzkt_operation.type, //string
            amount:        tzkt_operation.amount, //long
            parameters:    tzkt_operation.parameters, //string (instead of HEX)
            failed:        tzkt_operation.status !== "applied", //string
            internal:      tzkt_operation.nonce !== undefined, //int
            burn:          tzkt_operation.storageFee
                         + tzkt_operation.allocationFee, //long
            counter:       tzkt_operation.counter, //int
            fee:           tzkt_operation.bakerFee, //long
            gas_limit:     tzkt_operation.gasLimit, //int
            storage_limit: tzkt_operation.storageLimit * 1_000_000, //int
            op_level:      tzkt_operation.level, //int
            timestamp:     tzkt_operation.timestamp, //DateTime
            src: {
                tz:        tzkt_operation.sender.address  //string
            },
            destination: {
                tz:        tzkt_operation.target.address  //string
            },
        }
    }
}

# Tezos staking balance

/staking_balance/{address} 🡒 /accounts/{address}

var tzkt_account = get('/accounts/{address}');
var mystique_balance = [ tzkt_account.stakingBalance ];

# Balance from balance updates

/balance_from_balance_updates/{address} 🡒 /accounts/{address}

var tzkt_account = get('/accounts/{address}');
var mystique_balance = {
    spendable: tzkt_account.balance
             - tzkt_account.frozenRewards
             - tzkt_account.frozenFees
             - tzkt_account.frozenDeposits,  //long
    frozen:    tzkt_account.frozenRewards
             + tzkt_account.frozenFees
             + tzkt_account.frozenDeposits,  //long
    rewards:   tzkt_account.frozenRewards,   //long
    fees:      tzkt_account.frozenFees,      //long
    deposits:  tzkt_account.frozenDeposits   //long
}

# Network

/network 🡒 https://services.tzkt.io/v1/network

You can also use the following endpoints in case you have connectivity issues with test networks:

https://services.tzkt.io/zeronet/v1/network https://services.tzkt.io/carthagenet/v1/network https://services.tzkt.io/babylonnet/v1/network

# Contact us

Feel free to ask any questions. Baking Bad team is always happy to help!