-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1330 from Phala-Network/doc-comments
Enrich the doc on docs.rs for pink
- Loading branch information
Showing
16 changed files
with
856 additions
and
113 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,68 @@ | ||
<h1 align="center"> | ||
Phala's ink! for writing phat contracts | ||
</h1> | ||
<h1 align="center">Phala's ink! - Writing Enhanced Smart Contracts</h1> | ||
|
||
pink! is based on Parity's ink! language and provide some extra functionality to interact with phala's phat contract runtime. | ||
Pink! is a smart contract language extending Parity's `ink!`. It extends the basic functionality with additional features, tailored to interact efficiently with Phala's Phat Contract runtime. | ||
|
||
# Getting started | ||
## Getting Started | ||
|
||
The orignal `ink!` contract can run under Phala's phat contract platform without any modifacation. So you can follow Parity's `ink!` [documentation](https://paritytech.github.io/ink-docs/) to get started. | ||
Unaltered `ink!` contracts are fully compatible and executable on the Phala's Phat Contract platform. To learn how to start writing contracts with `ink!`, follow the Parity's [ink! documentation](https://paritytech.github.io/ink-docs/). | ||
|
||
If you want to use phat contract's specific features, such as phala-mq message, HTTP requests, you can use `pink_extension` to achieve this. See [examples](https://github.com/Phala-Network/phala-blockchain/tree/master/crates/pink/examples) for more detail. | ||
To get started with Pink!, add the following dependency to your `Cargo.toml`: | ||
|
||
```toml | ||
[dependencies] | ||
ink = { version = "4", default-features = false } | ||
pink = { package = "pink-extension", version = "0.4", default-features = false } | ||
|
||
[features] | ||
std = [ | ||
"ink/std", | ||
"pink/std", | ||
] | ||
``` | ||
|
||
Then, you can use the `http_get!` macro to make a GET request to a remote server: | ||
|
||
```ignore | ||
#[ink::message] | ||
fn http_get_example(&self) { | ||
let response = pink::http_get!("https://httpbin.org/get"); | ||
assert_eq!(response.status_code, 200); | ||
} | ||
``` | ||
|
||
## Phat Contract-Specific Features | ||
|
||
The Pink! crate is designed to empower you, enabling you to leverage the unique features of the Phat Contract, such as making HTTP requests as demonstrated in our examples. This crate supplies the crucial types and functions needed to seamlessly interact with the Phat Contract runtime. | ||
|
||
There are three kind of APIs to communication with the runtime: | ||
|
||
- Emitting Events: | ||
These APIs are primarily used in situations where the operation could lead to side effects that need to be deterministically recorded and may be rolled back during the execution of the contract call. For additional information on Emitting Events APIs, please refer to the [PinkEvent documentation](crate::PinkEvent). | ||
|
||
- Chain Extension: | ||
These APIs are predominantly used for read-only operations or operations that aren't expected to create deterministic side effects. For an in-depth understanding of Chain Extension APIs, please refer to the [PinkExt documentation](crate::chain_extension::PinkExtBackend). | ||
|
||
- System contract: | ||
There is a special contract called the System contract in each cluster. The system contract is instantiated when the cluster is created. Either ink contracts or external accounts can call the system contract to perform certain operations. For more information on the System contract, please refer to the [System documentation](crate::system::SystemForDoc). | ||
|
||
For practical implementation examples, explore our [Phat Contract examples](https://github.com/Phala-Network/phat-contract-examples) repository. | ||
|
||
## Using JavaScript with Phat Contract | ||
|
||
Phat Contract supports JavaScript through the [phat-quickjs](https://github.com/Phala-Network/phat-quickjs) contract. | ||
|
||
There are two ways to use JavaScript in your contract: | ||
|
||
- You can deploy your phat-quickjs contract instance through a standard deployment process. | ||
|
||
- However, for a more convenient approach, most public clusters should already have a public driver quickjs contract deployed. You can obtain the contract code_hash with `System::get_driver("JsDelegate")`. | ||
|
||
- For the simplest integration, consider using the [`phat_js`](https://docs.rs/phat_js/) crate. It provides an `eval` function that lets you evaluate JavaScript code snippets directly. | ||
For example: | ||
```ignore | ||
#[ink::message] | ||
fn eval_js_example(&self) { | ||
let result = phat_js::eval("'Hello,' + 'World'", &[]); | ||
assert_eq!(result, phat_js::Output::String("Hello,World".to_string())); | ||
} | ||
``` |
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
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
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
Oops, something went wrong.