Skip to main content

Unlock Conditions

Outputs can have different unlock conditions. This guide explains how to add them to an output.

Client in Wallet

If you are using a wallet you can always get the client by calling the client()/getClient()/get_client() method

Output Unlock Conditions

Different outputs can have different unlock conditions. This table shows you which output is compatible with which unlock condition. You can find the output specs in TIP-018

OutputAddressStorage Deposit ReturnTimelockExpirationState Controller AddressGovernor AddressImmutable Alias Address
Basicxxxx
Aliasxx
Foundryx
NFTxxxx

Example Code

The following example will use the create multiple outputs and add the following unlock_conditions using the add_unlock_condition function of each output type:

  1. StorageDepositReturnUnlockCondition.
sdk/examples/how_tos/outputs/unlock_conditions.rs
loading...
  1. TimelockUnlockCondition.
sdk/examples/how_tos/outputs/unlock_conditions.rs
loading...
  1. ExpirationUnlockCondition.
sdk/examples/how_tos/outputs/unlock_conditions.rs
loading...
  1. GovernorAddressUnlockCondition and StateControllerAddressUnlockCondition.
sdk/examples/how_tos/outputs/unlock_conditions.rs
loading...
  1. ImmutableAliasAddressUnlockCondition.
sdk/examples/how_tos/outputs/unlock_conditions.rs
loading...

Full Example Code

sdk/examples/how_tos/outputs/unlock_conditions.rs
loading...

Expected Output

[
{
"type": 3,
"amount": "42600",
"unlockConditions": [
{
"type": 0,
"address": {
"type": 0,
"pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"
}
}
]
},
{
"type": 3,
"amount": "46800",
"unlockConditions": [
{
"type": 0,
"address": {
"type": 0,
"pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"
}
},
{
"type": 1,
"returnAddress": {
"type": 0,
"pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"
},
"amount": "1000000"
}
]
},
{
"type": 3,
"amount": "43100",
"unlockConditions": [
{
"type": 0,
"address": {
"type": 0,
"pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"
}
},
{
"type": 2,
"unixTime": 1
}
]
},
{
"type": 3,
"amount": "46400",
"unlockConditions": [
{
"type": 0,
"address": {
"type": 0,
"pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"
}
},
{
"type": 3,
"returnAddress": {
"type": 0,
"pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"
},
"unixTime": 1
}
]
},
{
"type": 4,
"amount": "50300",
"aliasId": "0x0000000000000000000000000000000000000000000000000000000000000000",
"stateIndex": 0,
"stateMetadata": "0x",
"foundryCounter": 0,
"unlockConditions": [
{
"type": 4,
"address": {
"type": 0,
"pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"
}
},
{
"type": 5,
"address": {
"type": 0,
"pubKeyHash": "0x7ffec9e1233204d9c6dce6812b1539ee96af691ca2e4d9065daa85907d33e5d3"
}
}
]
},
{
"type": 5,
"amount": "52800",
"serialNumber": 1,
"tokenScheme": {
"type": 0,
"mintedTokens": "0x32",
"meltedTokens": "0x0",
"maximumSupply": "0x64"
},
"unlockConditions": [
{
"type": 6,
"address": {
"type": 8,
"aliasId": "0xe8506eb1dc96cbe3b24ef8102551328bfff767393389e824e7cef199e52d87b6"
}
}
]
}
]