Operations

Transaction

Let’s first take a look at the expected format of a transaction in JSON format.

{
    "kind": "transaction",
    "source": $contract_id,
    "fee": $mutez,
    "counter": $positive_bignum,
    "gas_limit": $positive_bignum,
    "storage_limit": $positive_bignum,
    "amount": $mutez,
    "destination": $contract_id,
    "parameters"?: $micheline.michelson_v1.expression
}

First we define with the kind value that it is a transaction operation we want to create. With the source value we decide what address we want to transfer the funds from. This can be the public key hash or a contract address that is spendable and where the public key hash is set as its manager. fee and amount expect a $mutez (1 XTZ = 10^6 mutez) value as a string. Every operation also includes a counter value as a protection mechanism against replay-attacks. The current counter value can be fetched from the RPC and incremented by one when creating a new operation. With gas_limit and storage_limit we set an upper limit on how much gas and storage the operation is allowed to use. The destination value is set to an address in the same way as for source. parameters is an optional key where the value can be an expression used for smart contract interaction.

A simple transaction of 1 XTZ could look something like this in JSON:

[
    {  
        "kind":"transaction",
        "source":"tz1WmhTgcckoDagACbXAxatWMKy7yesY349p",
        "fee":"1350",
        "counter":"1527770",
        "gas_limit":"10600",
        "storage_limit":"277",
        "amount":"1000000",
        "destination":"tz1aC53WoYEvdazinMMh8WfQZ5TPijeFfCUC"
    }
]

More about how to set the gas and storage limits can be found in the fee schedule section.

Reveal

Reveal is the first operation that need to be sent from a new address. This will reveal the public key associated to an address so that everyone can verify the signature for the operation and any future operations.

{
    "kind": "reveal",
    "source": $contract_id,
    "fee": $mutez,
    "counter": $positive_bignum,
    "gas_limit": $positive_bignum,
    "storage_limit": $positive_bignum,
    "public_key": $Signature.Public_key
}

The public_key value is the public key that we want to reveal. The other values are set in a similar way as for the transaction operation.

Since reveal must be the first operation it is often batched together with another operation. If the previous example transaction is the first operation from an address we would need the following JSON object:

[  
    {  
        "kind":"reveal",
        "source":"tz1WmhTgcckoDagACbXAxatWMKy7yesY349p",
        "fee":"0",
        "counter":"1527770",
        "gas_limit":"10000",
        "storage_limit":"0",
        "public_key":"edpkva47oZEvUyhonx13xfBBVckJDYHWXHUZmdoz7gxiZE8tW45FjK"
    },
    {  
        "kind":"transaction",
        "source":"tz1WmhTgcckoDagACbXAxatWMKy7yesY349p",
        "fee":"2650",
        "counter":"1527771",
        "gas_limit":"10600",
        "storage_limit":"277",
        "amount":"1000000",
        "destination":"tz1aC53WoYEvdazinMMh8WfQZ5TPijeFfCUC"
    }
]

To find out if we need to include a reveal operation a request can be sent to the RPC to see if a public key already have been revealed for the address.

Origination

{
    "kind": "origination",
    "source": $contract_id,
    "fee": $mutez,
    "counter": $positive_bignum,
    "gas_limit": $positive_bignum,
    "storage_limit": $positive_bignum,
    "manager_pubkey": $Signature.Public_key_hash,
    "balance": $mutez,
    "spendable"?: boolean,
    "delegatable"?: boolean,
    "delegate"?: $Signature.Public_key_hash,
    "script"?: $scripted.contracts
}

When originating a new account, we need to set a manager_pubkey. This will be the public key hash that will manage the account. With the script value we can add smart contract code to the contract. If we want to set a script value, spendable and delegatable must be set to false. An account that only will be used to delegate funds should have the spendable and delegateable values set to true. With the delegate value we can set an initial delegate address.

Delegation

{
    "kind": "delegation",
    "source": $contract_id,
    "fee": $mutez,
    "counter": $positive_bignum,
    "gas_limit": $positive_bignum,
    "storage_limit": $positive_bignum,
    "delegate"?: $Signature.Public_key_hash
}

With the delegate value we can set a new delegate address. This will override the previous address that the account have delegated to. If the delegate variable is not defined, we will undelegate.