-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Added docs for artifact files #2362
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
766530c
Added documentation for artifact files
96cdde7
Merge branch 'master' into arv/docs_artifacts
sirasistant 2e0939f
use literal names of properties
2410b37
Merge branch 'arv/docs_artifacts' of https://github.com/AztecProtocol…
5af4135
Merge branch 'master' into arv/docs_artifacts
sirasistant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Contract artifacts | ||
|
||
After compiling a contract you'll get a Contract Artifact file, that contains the data needed to interact with a specific contract, including its name, functions that can be executed, and the interface and code of those functions. Since private functions are not published in the Aztec network, you'll need this artifact file to be able to call private functions of contracts. | ||
|
||
The artifact file can be used with `aztec.js` to instantiate contract objects and interact with them. | ||
|
||
## Contract Artifact Structure | ||
|
||
The structure of a contract artifact is as follows: | ||
```json | ||
{ | ||
"name": "CardGame", | ||
"functions": [ | ||
{ | ||
"name": "constructor", | ||
"functionType": "secret", | ||
"isInternal": false, | ||
"parameters": [], | ||
"returnTypes": [], | ||
"bytecode": "...", | ||
"verificationKey": "..." | ||
}, | ||
{ | ||
"name": "on_card_played", | ||
"functionType": "open", | ||
"isInternal": true, | ||
"parameters": [ | ||
{ | ||
"name": "game", | ||
"type": { | ||
"kind": "integer", | ||
"sign": "unsigned", | ||
"width": 32 | ||
}, | ||
"visibility": "private" | ||
}, | ||
{ | ||
"name": "player", | ||
"type": { | ||
"kind": "field" | ||
}, | ||
"visibility": "private" | ||
}, | ||
{ | ||
"name": "card_as_field", | ||
"type": { | ||
"kind": "field" | ||
}, | ||
"visibility": "private" | ||
} | ||
], | ||
"returnTypes": [ | ||
... | ||
], | ||
"bytecode": "...", | ||
"verificationKey": "..." | ||
}, | ||
... | ||
] | ||
} | ||
|
||
``` | ||
|
||
### Contract Name | ||
It is a simple string that matches the name that the contract developer used for this contract in noir. It's used for logs and errors. | ||
|
||
### Functions | ||
A contract is a collection of several functions that can be called. Each function has the following properties: | ||
|
||
#### Name | ||
A simple string that matches the name that the contract developer used for this function in noir. For logging and debugging purposes. | ||
|
||
#### Function Type | ||
The functionType can have one of the following values: | ||
|
||
- Secret: The function is ran and proved locally by the clients, and its bytecode not published to the network. | ||
- Open: The function is ran and proved by the sequencer, and its bytecode is published to the network. | ||
- Unconstrained: The function is ran locally by the clients to generate digested information useful for the user. It's not meant to be transacted against. | ||
|
||
#### Internal Flag | ||
The isInternal property is a boolean that indicates whether the function is internal to the contract and cannot be called from outside. | ||
|
||
#### Parameters | ||
Each function can have multiple parameters that are arguments to execute the function. Parameters have a name, and type (like integers, strings, or complex types like arrays and structures). | ||
|
||
#### Return Types | ||
The returnTypes property defines the types of values that the function returns after execution. | ||
|
||
#### Bytecode | ||
The bytecode is a string representing the compiled ACIR of the function, ready for execution on the network. | ||
|
||
#### Verification Key (Optional) | ||
The verificationKey is an optional property that contains the verification key of the function. This key is used to verify the proof of the function execution. | ||
|
||
### Debug Metadata (Optional) | ||
Although not significant for non-developer users, it is worth mentioning that there is a debug section in the contract artifact which helps contract developers to debug and test their contracts. This section mainly contains debug symbols and file maps that link back to the original source code. | ||
|
||
## Understanding Parameter and Return Types | ||
To make the most of the functions, it's essential to understand the types of parameters and return values. Here are some common types you might encounter: | ||
|
||
- Field: A basic type representing a field element in the finite field of the curve used in the Aztec protocol. | ||
- Boolean: A simple true/false value. | ||
- Integer: Represents whole numbers. It has attributes defining its sign (positive or negative) and width (the number of bits representing the integer). | ||
- Array: Represents a collection of elements, all of the same type. It has attributes defining its length and the type of elements it holds. | ||
- String: Represents a sequence of characters with a specified length. | ||
- Struct: A complex type representing a structure with various fields, each having a specific type and name. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make the titles the same as the keys in the artifact? Will be easier to find the description :)