The content below will guide wasm contract developers on what access operations to include in their wasm dependencies based on what messages and queries they use.
- Deploy and instantiate your Wasm Contract to Sei blockchain
- Create a dependency mapping json file according to the Dependency Mapping Template
- Add Wasm Contract Base Dependencies to the dependency json
- Follow the Module Specific Dependencies section to add extensive dependencies
- Follow Integration and Debugging steps to verify the dependency json before deploying
Below is a template that you can use to register dependency mapping to your contract:
{
"wasm_dependency_mapping": {
"contract_address": "{your-wasn-contract-address}",
"base_access_ops": [
// add access operations here
]
}
}
Make sure to replace the contract_address placeholder with the correct address, and add basic Wasm Contract Base Dependencies and extensive Module Specific Dependencies if needed.
There are certain base dependencies required for wasm contract parallelization, and are outlined below. For these, you'll need your wasm contract address (sei....) and also the code ID of the wasm contract (with the value represented as a hex prefixed by zeroes with a length of 16). This code ID is obtained from the response when initially storing the code for your contract.
Example:
Code ID 2: 0000000000000002
Code ID 47: 000000000000002F
{
"operation": {
"access_type": "WRITE",
"resource_type": "KV_WASM_CONTRACT_STORE",
"identifier_template": "03%s"
},
"selector_type": "CONTRACT_ADDRESS",
"selector": "{your-contract-address}"
},
{
"operation": {
"access_type": "READ",
"resource_type": "KV_WASM_CONTRACT_STORE",
"identifier_template": "03%s"
},
"selector_type": "CONTRACT_ADDRESS",
"selector": "{your-contract-address}"
},
{
"operation": {
"access_type": "READ",
"resource_type": "KV_WASM_CODE",
"identifier_template": "01{code-id-hex-prefixed-with-zeros-with-length-16}"
},
"selector_type": "NONE"
},
{
"operation": {
"access_type": "READ",
"resource_type": "KV_WASM_PINNED_CODE_INDEX",
"identifier_template": "07{code-id-hex-prefixed-with-zeros-with-length-16}"
},
"selector_type": "NONE"
},
{
"operation": {
"access_type": "READ",
"resource_type": "KV_WASM_CONTRACT_ADDRESS",
"identifier_template": "02%s"
},
"selector_type": "CONTRACT_ADDRESS",
"selector": "{your-wasm-contract-address}"
},
{% hint style="warning" %} Make sure you provide the correct code-id-hex-prefixed-with-zeros-with-length-16 and your-wasm-contract-address {% endhint %}
Additionally, at the end of the dependencies specified for the wasm contract, you'll need to add a COMMIT access operation:
{
"operation": {
"access_type": "COMMIT",
"resource_type": "ANY",
"identifier_template": "*"
},
"selector_type": "NONE"
}
The different execution paths of your smart contract may have different resource usages, and to parallelize in the most optimal way, it is possible to define resource dependencies that are specific to the message being sent to the contract. Using this approach, the base access ops can remain simpler and cover the common resource usages, and these message specific dependencies can be used to declare resources for certain messages that may be more computationally expensive or use many resources.
The format for the message specific dependencies is the exact same as for base dependencies, with the caveat being that they are only appended to the contract dependency if/when that specific message is called for the contract.
The execute message dependencies can be used to map these message specific dependencies to the execute message that utilizes those resources. They can be added in a section called execute_access_ops
added along with base_access_ops
in the json mapping file.
When the contract is called with an execute message that has these message specific dependencies, the specific dependencies are appended to the base_access_ops
to construct the holistic contract dependencies.
Example:
{
"wasm_dependency_mapping": {
"contract_address": "{your-wasn-contract-address}",
"base_access_ops": [
// add access operations here
],
"execute_access_ops": [
{
"message_name": "{execute-message-name}",
"wasm_operations": [
// Add access operations here (specific to the execute message)
]
},
{
"message_name": "{other-execute-message-name}",
"wasm_operations": [
// Add access operations here (specific to the execute message)
]
}
]
}
}
The query message dependencies can be used to map these message specific dependencies to the query message that utilizes those resources. They can be added in a section called query_access_ops
added along with base_access_ops
in the json mapping file.
When the contract is called with a query message that has these message specific dependencies, the specific dependencies are appended to the base_access_ops
to construct the holistic contract dependencies.
These are more relevant for other contracts that may want to query your smart contract, since they would utilize the dependencies specified by this contract for proper parallelization.
Example:
{
"wasm_dependency_mapping": {
"contract_address": "{your-wasn-contract-address}",
"base_access_ops": [
// add access operations here
],
"query_access_ops": [
{
"message_name": "{query-message-name}",
"wasm_operations": [
// Add access operations here (specific to the execute message)
]
},
{
"message_name": "{other-query-message-name}",
"wasm_operations": [
// Add access operations here (specific to the execute message)
]
}
]
}
}
A Wasm contract may query
or call
(using SubMsg
in the response) other modules of the Sei blockchain. These requests represents READ/WRITE invocations to the corresponding the resources and need to be defined in your dependency mapping. In this section, we will provide guidance for how to write access operation for different types of request. Below are the subpages for dependencies needed for each module based on the functionality used from that module by the wasm contract.
Module | Request Types |
---|---|
Bank Send | |
Create Denom Mint Burn |