Smart Contract Utilities
Learn how to use the Anvil API to interact with smart contract scripts. Endpoints for deriving addresses, applying parameters, and serializing/parsing Plutus data.
Smart Contract Utilities provides endpoints for interacting with Plutus scripts (also known as validators). You can use these endpoints to derive addresses, apply parameters, and handle data serialization.
GET /validators/{hash}/address
Derives the script address from a given script hash.
POST /validators/{hash}/apply-params
Applies parameters to a script to generate a new, parameterized script hash.
POST /validators/{hash}/parse
Parses a hex-encoded datum or redeemer into a human-readable JSON object.
POST /validators/{hash}/serialize
Serializes a JSON object into a hex-encoded datum or redeemer string.
Available Endpoints
Get Script Address
GET /validators/{hash}/address
Derives the script address from a given script hash.
Path Parameters:
hash
(string): The hex-encoded hash of the Plutus script.
Query Parameters:
stake
(string, optional): A stake key hash to associate with the address.
Apply Parameters to Script
POST /validators/{hash}/apply-params
Applies a set of parameters to a parameterized script, returning the new script hash and compiled code. See Hello World Example with Parameters for an example of a smart contract that uses parameters.
Path Parameters:
hash
(string): The hash of the original parameterized script.
Body:
purpose
(string): The purpose of the script, which determines the context in which it's validated. Possible values are:"mint"
: For minting or burning assets."spend"
: For spending transaction outputs from the script address."withdraw"
: For withdrawing staking rewards."publish"
: For publishing delegation certificates."vote"
: For voting on governance proposals."propose"
: For executing constitution guardrails when submitting governance proposals.
params
(array): An array of parameters to apply to the script. e.g. owner key hash, or UTXO reference of assets on the smart contract.blueprint
(object, optional): Only required if the script is not yet known to Anvil. This is usually yourplutus.json
file from an Aiken build. See the Blueprint Management guide for more details.
Parse Plutus Data
POST /validators/{hash}/parse
Parses a hex-encoded Plutus data string (e.g., datum or redeemer) into a structured JSON object based on the script's schema.
Path Parameters:
hash
(string): The hash of the script. The API uses this hash to fetch the validator's schema, which is required to correctly convert the data between JSON and its hex-encoded format.
Body:
type
(string): The type of data to parse ("datum"
or"redeemer"
).purpose
(string): The purpose of the script, which determines the context in which it's validated. Possible values are:"mint"
: For minting or burning assets."spend"
: For spending transaction outputs from the script address."withdraw"
: For withdrawing staking rewards."publish"
: For publishing delegation certificates."vote"
: For voting on governance proposals."propose"
: For executing constitution guardrails when submitting governance proposals.
data
(object): An object containing the hex string:{ "hex": "..." }
.addressFormat
(string, optional): The desired address format ("bech32"
or"raw"
).blueprint
(object, optional): The CIP-57 blueprint if the script is not yet known to Anvil. See the Blueprint Management guide for more details.
Serialize Plutus Data
POST /validators/{hash}/serialize
Serializes a JSON object into a hex-encoded Plutus data string based on the script's schema. The opposite of parse.
Path Parameters:
hash
(string): The hash of the script. The API uses this hash to fetch the validator's schema, which is required to correctly convert the data between JSON and its hex-encoded format.
Body:
type
(string): The type of data to serialize ("datum"
or"redeemer"
).purpose
(string): The purpose of the script, which determines the context in which it's validated. Possible values are:"mint"
: For minting or burning assets."spend"
: For spending transaction outputs from the script address."withdraw"
: For withdrawing staking rewards."publish"
: For publishing delegation certificates."vote"
: For voting on governance proposals."propose"
: For executing constitution guardrails when submitting governance proposals.
data
(object): The JSON object to serialize.blueprint
(object, optional): The CIP-57 blueprint if the script is not yet known to Anvil. See the Blueprint Management guide for more details.
Last updated
Was this helpful?