# CKB Script ABI
## Metadata
**Status**:: #x
**Zettel**:: #zettel/fleeting
**Created**:: [[2025-12-18]]
**Topic**:: [[♯ CKB]]
## Synopsis
If we consider script args and witness as the input to script, they acts as the public interface. So maybe we can use the schema for script args and witness as CKB script ABI.
For example, this is the interface for secp256k1 lock script.
```
array Byte20 [byte; 20];
array Byte32 [byte; 32];
struct Args {
pubkey_hash: Byte20,
}
struct Witness {
pubkey: Byte32,
signature: Byte32,
}
```
It's easy to compute the canonical hash of the schema as well:
- Turn the molecule schema into AST
- Expand fields in Args and Witness recursively so they only contain the builtin molecule types as leaves.
- Strip type and field names.
- Concatenate the expanded ASTs for Args and Witness and compute the hash.
To avoid accidental conflicts, we can include a name in the hash.
How to associate the schema to a script?
Use a well-known type script to register schema info for scripts. The type script accepts script data hash as args. If we want to look up the schema for a script with data hash D, we just search a cell with type script hash = `H(schema registry type script, D)`. The data contains the canonical hash and the compact AST (before expanding). The well-known type script can verify that the canonical hash matches the AST.