-
Notifications
You must be signed in to change notification settings - Fork 16
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 #512 from LF-Decentralized-Trust-labs/pub-storage-…
…tutorial Enhance Onboarding with Expanded Tutorial Series
- Loading branch information
Showing
55 changed files
with
3,235 additions
and
98 deletions.
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
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,152 @@ | ||
# Hello World with Paladin | ||
|
||
This tutorial walks you through deploying and interacting with a simple `HelloWorld` smart contract using the Paladin SDK. The example demonstrates how to: | ||
1. Deploy the contract, | ||
2. Interact with it by calling its `sayHello` function, | ||
3. Retrieve and verify the emitted event. | ||
|
||
--- | ||
|
||
## Running the Example | ||
|
||
The example code can be found in the [Paladin example repository](https://github.com/LF-Decentralized-Trust-labs/paladin/blob/main/example/helloworld). | ||
|
||
The HelloWorld solidity contract can be found [here](https://github.com/LF-Decentralized-Trust-labs/paladin/blob/main/solidity/contracts/tutorial/HelloWorld.sol). | ||
|
||
Follow the [Getting Started](../../getting-started/installation/) instructions to set up a Paladin environment. Then, follow the example [README](https://github.com/LF-Decentralized-Trust-labs/paladin/blob/main/example/helloworld/README.md) to run the code. | ||
|
||
--- | ||
|
||
### Overview | ||
|
||
We have a `HelloWorld` smart contract, which: | ||
- Emits a "welcome" message as an event when its `sayHello` function is called. | ||
|
||
### Key Artifacts | ||
To deploy and interact with the contract, we use: | ||
1. **ABI**: Describes the contract's interface, including its functions and events. | ||
2. **Bytecode**: The compiled contract code. | ||
|
||
These are pre-compiled and provided in the `helloWorldJson` object. | ||
|
||
--- | ||
|
||
To address the PR comment and clarify the differences between **contract deployment** and **function invocation**, here’s a revised version of the tutorial with an explicit callout: | ||
|
||
--- | ||
|
||
### Step 1: Deploy the Contract | ||
|
||
```typescript | ||
const deploymentTxID = await paladin.sendTransaction({ | ||
type: TransactionType.PUBLIC, | ||
abi: helloWorldJson.abi, | ||
bytecode: helloWorldJson.bytecode, | ||
from: owner.lookup, | ||
data: {}, | ||
}); | ||
``` | ||
|
||
#### Key Differences (vs. calling a contract function) | ||
- **Deployment requires `bytecode`**, as it is creating a new contract on the blockchain. | ||
- **No `to` address is specified**, since a contract does not yet exist at this stage. | ||
- **No specific function is called**, since this is an initial deployment. | ||
|
||
#### What happens: | ||
- The `sendTransaction` method sends a deployment transaction to the blockchain via Paladin. | ||
- The function returns a `deploymentTxID` that uniquely identifies the transaction. | ||
|
||
--- | ||
|
||
### Step 2: Confirm the Deployment | ||
|
||
```typescript | ||
const deploymentReceipt = await paladin.pollForReceipt(deploymentTxID, 10000, true); | ||
if (!deploymentReceipt?.contractAddress) { | ||
logger.error("Deployment failed!"); | ||
return false; | ||
} | ||
logger.log("Contract deployed successfully at address:", deploymentReceipt.contractAddress); | ||
``` | ||
|
||
#### What happens: | ||
- We use `pollForReceipt` to wait for the deployment transaction to be confirmed. | ||
- If successful, the receipt includes the new `contractAddress`, which we will use in the next step. | ||
|
||
--- | ||
|
||
### **Step 3: Call the `sayHello` Function** | ||
|
||
```typescript | ||
const name = "Paladin User"; // Example name for the greeting | ||
|
||
const sayHelloTxID = await paladin.sendTransaction({ | ||
type: TransactionType.PUBLIC, | ||
abi: helloWorldJson.abi, | ||
function: "sayHello", | ||
from: owner.lookup, | ||
to: deploymentReceipt.contractAddress, | ||
data: { name: name }, | ||
}); | ||
``` | ||
|
||
#### **Key Differences (vs. contract deployment)** | ||
- **Function calls require a `to` address**, since the contract already exists. | ||
- **No `bytecode` is needed**, as we are invoking an existing contract, not creating one. | ||
- **A specific function (`sayHello`) is provided**, along with its arguments in `data`. | ||
|
||
#### **What happens:** | ||
- The `sendTransaction` method sends a transaction to call the `sayHello` function of the deployed contract. | ||
- The `data` object includes the function arguments—in this case, the `name` of the person being greeted. | ||
|
||
--- | ||
|
||
### Step 4: Confirm the Function Call | ||
|
||
```typescript | ||
const functionReceipt = await paladin.pollForReceipt(sayHelloTxID, 10000, true); | ||
if (!functionReceipt?.transactionHash) { | ||
logger.error("Receipt retrieval failed!"); | ||
return false; | ||
} | ||
logger.log("sayHello function executed successfully!"); | ||
``` | ||
|
||
- **What happens**: | ||
- Similar to the deployment step, we wait for confirmation of the `sayHello` function call using `pollForReceipt`. | ||
|
||
--- | ||
|
||
### Step 5: Retrieve the Emitted Event | ||
|
||
```typescript | ||
const events = await paladin.decodeTransactionEvents( | ||
functionReceipt.transactionHash, | ||
helloWorldJson.abi, | ||
"pretty=true", | ||
); | ||
|
||
logger.log(events[0].data["message"]); | ||
``` | ||
|
||
- **What happens**: | ||
- We use `decodeTransactionEvents` to extract event data from the `sayHello` transaction. | ||
|
||
--- | ||
|
||
## Conclusion | ||
|
||
Congratulations! You've successfully: | ||
1. Deployed the `HelloWorld` contract, | ||
2. Called its `sayHello` function, | ||
3. Retrieved and validated the emitted event. | ||
|
||
This simple example demonstrates how to interact with smart contracts using the Paladin SDK. | ||
|
||
--- | ||
|
||
## Next Steps | ||
|
||
Now that you’ve deployed and interacted with the `HelloWorld` contract, you’re ready to explore more complex interactions with smart contracts. In the next tutorial, we will introduce you to a **Storage** contract where you will write and read from from the blockchain! | ||
|
||
[Continue to the Storage Contract Tutorial →](./public-storage.md) |
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,34 +1,56 @@ | ||
## Pre-requisites | ||
## Prerequisites | ||
|
||
* git | ||
* [NodeJS 20.x or newer](https://nodejs.org/en/download/package-manager) installed | ||
- **Git** | ||
- **Node.js 20.x or newer** | ||
Follow the [official Node.js documentation](https://nodejs.org/en/download/package-manager) for your platform to install the appropriate version. | ||
|
||
Clone the Paladin repository to access the examples: | ||
To access the tutorial code, clone the Paladin repository: | ||
|
||
```shell | ||
git clone https://github.com/LF-Decentralized-Trust-labs/paladin.git | ||
``` | ||
|
||
## Next Steps | ||
|
||
The tutorials on this page provide an introduction to building on the Paladin platform. If you haven’t already, visit the [Getting Started guide](../getting-started/installation.md) to familiarize yourself with running Paladin before proceeding with any of the tutorials below. | ||
|
||
The tutorials on this page provide a starting point for running code on top of Paladin. | ||
<div class="grid cards" markdown> | ||
|
||
If you haven't already, you should visit [Getting Started](../getting-started/installation/) to | ||
ensure you're familiar with running Paladin before walking through any of the tutorials. | ||
- :fontawesome-solid-rocket:{ .lg .middle } **[Hello World](hello-world.md)** | ||
|
||
--- | ||
|
||
Begin with a simple “Hello World” example to get familiar with some of the basics. | ||
|
||
- :fontawesome-solid-rocket:{ .lg .middle } **[Public Storage](public-storage.md)** | ||
|
||
--- | ||
|
||
Explore fundamental SDK functionality for deploying and interacting with a publicly visible contract. | ||
|
||
- :fontawesome-solid-rocket:{ .lg .middle } **[Private Storage](private-storage.md)** | ||
|
||
--- | ||
|
||
Discover how to use **Privacy Groups** and keep contract data confidential among authorized members. | ||
|
||
- :fontawesome-solid-rocket:{ .lg .middle } **[Notarized Tokens](notarized-tokens.md)** | ||
|
||
--- | ||
|
||
Learn how to issue, mint, and transfer tokens using Paladin’s **Notarized Tokens** domain. | ||
|
||
<div class="grid cards" markdown> | ||
|
||
- :fontawesome-solid-stamp:{ .lg .middle } __[Bond Issuance](bond-issuance.md)__ | ||
- :fontawesome-solid-stamp:{ .lg .middle } **[Wholesale CBDC](zkp-cbdc.md)** | ||
|
||
--- | ||
--- | ||
|
||
Learn how Noto and Pente work together to represent a bond issuance process. | ||
Implement a wholesale CBDC with **zero-knowledge proof** features for enhanced privacy and regulatory compliance. | ||
|
||
- :fontawesome-solid-stamp:{ .lg .middle } __[Wholesale CBDC](zkp-cbdc.md)__ | ||
- :fontawesome-solid-stamp:{ .lg .middle } **[Bond Issuance](bond-issuance.md)** | ||
|
||
--- | ||
--- | ||
|
||
Learn how to implement a wholesale CBDC with Zeto. | ||
Understand how **Notarized Tokens** and **Privacy Groups** work together to model and manage a bond issuance process. | ||
|
||
</div> | ||
</div> |
Oops, something went wrong.