Skip to content

Commit 80776f4

Browse files
authored
Docs x warden contract (#1165)
* added a sample contract for calling x/warden * finalized the smart contract guide + small fixes * coderabbit * consolidated improvements in precompile docs
1 parent e0785e4 commit 80776f4

File tree

15 files changed

+204
-102
lines changed

15 files changed

+204
-102
lines changed

docs/developer-docs/docs/build-an-app/deploy-smart-contracts-on-warden/deploy-a-cross-chain-app.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ Here are the key features of this contract:
3838

3939
Before you start, complete the following prerequisites:
4040

41-
1. Install `node.js` and `npm`.
42-
2. Install `truffle` globally: `npm install -g truffle`.
43-
3. Create a wallet and get Sepolia ETH – for example, from the [PoW Sepolia Faucet](https://sepolia-faucet.pk910.de).
44-
4. Create an [Infura](https://www.infura.io) account for accessing the Sepolia network.
41+
- Install `node.js` and `npm`.
42+
- Install `truffle` globally: `npm install -g truffle`.
43+
- Create a wallet and get Sepolia ETH – for example, from the [PoW Sepolia Faucet](https://sepolia-faucet.pk910.de).
44+
- Create an [Infura](https://www.infura.io) account for accessing the Sepolia network.
4545

4646
### 1.1. Set up the project
4747

docs/developer-docs/docs/build-an-app/deploy-smart-contracts-on-warden/deploy-an-evm-contract.md

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,6 @@ To deploy an EVM contract locally, you need to run a local chain and make sure i
7272
</TabItem>
7373
</Tabs>
7474

75-
5. You'll also need your chain ID. Run the following and note down the value from the `network` field:
76-
77-
```bash
78-
wardend status
79-
```
80-
81-
:::tip
82-
If you used our `just` script to run the node with default settings, the chain ID is `warden_1337-1`.
83-
:::
84-
8575
### Option 2. Connect to Chiado
8676

8777
To deploy an EVM contract on [Chiado testnet](/operate-a-node/chiado-testnet/chiado-overview), you need to install its binary and fund your key, as shown in the following steps:
@@ -134,22 +124,16 @@ To deploy an EVM contract on [Chiado testnet](/operate-a-node/chiado-testnet/chi
134124

135125
## 2. Create an EVM project
136126

137-
1. Create a new directory `/warden-smart-contract` for your project and navigate there:
138-
139-
```bash
140-
mkdir warden-smart-contract
141-
cd warden-smart-contract
142-
```
143-
144-
2. Initialize a new Foundry project:
127+
Initialize a new Foundry project and navigate to its directory:
145128

146-
```bash
147-
forge init --no-commit
148-
```
129+
```bash
130+
forge init warden-smart-contract --no-commit
131+
cd warden-smart-contract
132+
```
149133

150134
## 3. Create a smart contract
151135

152-
After you initialize a Foundry project, the script will automatically create a sample contract named `Counter` in the `/src` directory:
136+
After you initialize a Foundry project, the script will automatically create a sample contract named `Counter.sol` in the `/src` directory:
153137

154138
```sol title="/warden-smart-contract/src/Counter.sol"
155139
// SPDX-License-Identifier: UNLICENSED
@@ -352,5 +336,5 @@ After deploying a basic EVM smart contract, start using Warden precompiles to ca
352336
See the following sections:
353337

354338
- [Call Warden modules in your contract](/category/interact-with-warden-modules)
355-
- [Solidity precompiles](/category/precompiles)
339+
- [Precompiles](/category/precompiles)
356340

docs/developer-docs/docs/build-an-app/interact-with-warden-modules/get-started.md

Lines changed: 105 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 1
2+
sidebar_position: 2
33
---
44

55
import Tabs from '@theme/Tabs';
@@ -9,37 +9,91 @@ import TabItem from '@theme/TabItem';
99

1010
## Overview
1111

12-
This guide shows how to prepare an EVM smart contract for interacting with [Warden Protocol modules](/category/warden-protocol-modules).
12+
You can interact with [Warden Protocol modules](/category/warden-protocol-modules) in your EVM smart contract by calling [Warden precompiles](/category/precompiles).
1313

14-
You're going to call modules from your contract by using functions from the available [Warden precompiles](/category/precompiles).
14+
This guide shows how to deploy a simple EVM contract calling the [`spaceById()`](../precompiles/x-warden#query-a-space-by-id) function of the [`x/warden`](../precompiles/x-warden) module. After that, you'll be able to expand your contract code with other functions, which are documented in the subsections below.
15+
16+
To learn the basics of deploying contracts on Warden, refer to [Deploy an EVM contract](../deploy-smart-contracts-on-warden/deploy-an-evm-contract).
1517

1618
## Prerequisites
1719

1820
Before you start, complete the following prerequisites:
1921

20-
1. [Install Foundry](https://book.getfoundry.sh/getting-started/installation) by running this command:
22+
- [Install Foundry](https://book.getfoundry.sh/getting-started/installation) by running this command:
2123

2224
```bash
2325
curl -L https://foundry.paradigm.xyz | bash \
2426
foundryup
2527
```
2628

27-
2. [Prepare the chain](../deploy-smart-contracts-on-warden/deploy-an-evm-contract#1-prepare-the-chain), setting up your private key.
29+
- Prepare the chain, setting up your private key. You can either run a local chain or join the Chiado testnet, as shown in [Deploy an EVM smart contract](../deploy-smart-contracts-on-warden/deploy-an-evm-contract#1-prepare-the-chain).
2830

29-
## 1. Create a project and contract
31+
## 1. Create your project and contract
3032

3133
1. Initialize a new Foundry project and navigate to its directory:
32-
34+
3335
```bash
3436
forge init warden-smart-contract --no-commit
3537
cd warden-smart-contract
3638
```
39+
40+
Alternatively, you can use an existing project – for example, the one you created when following the [Deploy an EVM contract](../deploy-smart-contracts-on-warden/deploy-an-evm-contract) guide.
3741

3842
2. In the `/src` directory, create a new contract named `Warden.sol`.
3943

40-
3. Finally, prepare the contract code. You can use code samples from the following sections:
44+
To call a precompile in your contract, do this::
4145

42-
- [Interact with x/warden](/category/interact-with-xwarden)
46+
- Define an `interface` for interacting with a [Warden precompile](/category/precompiles).
47+
- Add a `contract` with functions calling the precompile.
48+
- In the `contract` section, you should also reference the precompile address.
49+
50+
You can use the example contract below. It calls the [`spaceById()`](../precompiles/x-warden#query-a-space-by-id) function of [`x/warden`](../precompiles/x-warden) to return a Space and its creator by Space ID:
51+
52+
```solidity title="/warden-smart-contract/src/Warden.sol"
53+
// SPDX-License-Identifier: UNLICENSED
54+
pragma solidity ^0.8.13;
55+
56+
// An interface for interacting with the IWarden precompile
57+
interface IWarden {
58+
59+
// A function for getting a Space by its ID
60+
function spaceById(uint64) external view returns (Space memory);
61+
62+
// Data structure representing a Warden Space
63+
struct Space {
64+
uint64 id; // The Space ID
65+
address creator; // The Space creator address
66+
address[] owners;
67+
uint64 nonce;
68+
uint64 approveAdminTemplateId;
69+
uint64 rejectAdminTemplateId;
70+
uint64 approveSignTemplateId;
71+
uint64 rejectSignTemplateId;
72+
}
73+
}
74+
75+
// A contract for interacting with the IWarden precompile
76+
contract querySpace {
77+
78+
// The IWarden precompile address
79+
address constant WARDEN_ADDRESS = 0x0000000000000000000000000000000000000900;
80+
IWarden public warden;
81+
82+
constructor() {
83+
warden = IWarden(WARDEN_ADDRESS);
84+
}
85+
86+
// A function for getting a Space by Space ID
87+
function getSpace(uint64 id) external view returns (IWarden.Space memory) {
88+
return warden.spaceById(id);
89+
}
90+
91+
// A function for getting the Space creator address by Space ID
92+
function getSpaceCreator(uint64 id) external view returns (address) {
93+
return warden.spaceById(id).creator;
94+
}
95+
}
96+
```
4397

4498
## 2. Compile and deploy the contract
4599

@@ -73,7 +127,7 @@ Before you start, complete the following prerequisites:
73127
3. Deploy the contract:
74128

75129
```bash
76-
forge create --rpc-url $RPC_URL --private-key $PRIVATE_KEY src/Warden.sol:WardenContract
130+
forge create --rpc-url $RPC_URL --private-key $PRIVATE_KEY src/Warden.sol:querySpace
77131
```
78132

79133
4. Export your contract address returned in `Deployed to`:
@@ -88,9 +142,47 @@ Before you start, complete the following prerequisites:
88142
cast code $CONTRACT_ADDRESS --rpc-url $RPC_URL
89143
```
90144

145+
## 3. Interact with the contract
146+
147+
Now you can interact with the contract.
148+
149+
1. If you're using a local chain, make sure it's running and there is at least one Space:
150+
151+
```
152+
wardend query warden spaces
153+
```
154+
155+
If nothing is returned, [create a Space](/operate-a-node/run-a-local-chain#create-a-space).
156+
157+
2. Get a Space by its ID – for example, `1`:
158+
159+
```
160+
cast call $CONTRACT_ADDRESS "getSpace(uint64)" 1 --rpc-url $RPC_URL
161+
```
162+
163+
The result will look like this:
164+
165+
```
166+
0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006ea8ac1673402989e7b653ae4e83b54173719c3000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006ea8ac1673402989e7b653ae4e83b54173719c30
167+
```
168+
169+
3. Get the Space creator by Space ID – for example, `1`:
170+
171+
```
172+
cast call $CONTRACT_ADDRESS "getSpaceCreator(uint64)" 1 --rpc-url $RPC_URL
173+
```
174+
175+
The result will look like this:
176+
177+
```
178+
0x0000000000000000000000006ea8ac1673402989e7b653ae4e83b54173719c30
179+
```
180+
91181
## Next steps
92182

93-
- To dive deeper and find code samples for each function from Warden precompiles, see the following guides:
183+
Now you can dive deeper and expand your contract with other functions from Warden precompiles:
184+
185+
- To find code samples for each function, see the following guides:
94186
- [Interact with x/warden](/category/interact-with-xwarden)
95-
- *Other modules: coming soon.*
96-
- For an overview of the functions, refer to the [Precompiles](/category/precompiles) section.
187+
- *Other modules: coming soon*
188+
- For an overview of the available functions, refer to the [Precompiles](/category/precompiles) section.

docs/developer-docs/docs/build-an-app/interact-with-warden-modules/interact-with-x-warden/_category_.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"position": 2,
2+
"position": 3,
33
"label": "Interact with x/warden",
44
"collapsible": true,
55
"collapsed": true,

docs/developer-docs/docs/build-an-app/interact-with-warden-modules/interact-with-x-warden/manage-key-requests.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ This article explains how to use `x/warden` to manage [key requests](/learn/glos
1313
To understand how to set up and deploy your project, see [Get started](../get-started.md).
1414

1515
:::tip
16-
For an overview of `x/warden` functions, refer to [Precompiles: x/warden](../../precompiles/x-warden#key-requests)
16+
- For an overview of `x/warden` functions, refer to [Precompiles: x/warden](../../precompiles/x-warden#key-requests).
17+
- The precompile address is `0x0000000000000000000000000000000000000900`.
1718
:::
1819

1920
## Create a new key request

docs/developer-docs/docs/build-an-app/interact-with-warden-modules/interact-with-x-warden/manage-keychains.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ This article explains how to use `x/warden` to manage [Keychains](/learn/glossar
1313
To understand how to set up and deploy your project, see [Get started](../get-started.md).
1414

1515
:::tip
16-
For an overview of `x/warden` functions, refer to [Precompiles: x/warden](../../precompiles/x-warden#keychains)
16+
- For an overview of `x/warden` functions, refer to [Precompiles: x/warden](../../precompiles/x-warden#keychains).
17+
- The precompile address is `0x0000000000000000000000000000000000000900`.
1718
:::
1819

1920
## Create a new Keychain

docs/developer-docs/docs/build-an-app/interact-with-warden-modules/interact-with-x-warden/manage-keys.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ This article explains how to use `x/warden` to manage [keys](/learn/glossary#key
1313
To understand how to set up and deploy your project, see [Get started](../get-started.md).
1414

1515
:::tip
16-
For an overview of `x/warden` functions, refer to [Precompiles: x/warden](../../precompiles/x-warden#keys)
16+
- For an overview of `x/warden` functions, refer to [Precompiles: x/warden](../../precompiles/x-warden#keys).
17+
- The precompile address is `0x0000000000000000000000000000000000000900`.
1718
:::
1819

1920
## Update a key

docs/developer-docs/docs/build-an-app/interact-with-warden-modules/interact-with-x-warden/manage-signature-requests.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ This article explains how to use `x/warden` to manage [signature requests](/lear
1313
To understand how to set up and deploy your project, see [Get started](../get-started.md).
1414

1515
:::tip
16-
For an overview of `x/warden` functions, refer to [Precompiles: x/warden](../../precompiles/x-warden#signature-requests)
16+
- For an overview of `x/warden` functions, refer to [Precompiles: x/warden](../../precompiles/x-warden#signature-requests).
17+
- The precompile address is `0x0000000000000000000000000000000000000900`.
1718
:::
1819

1920
## Create a new signature request

docs/developer-docs/docs/build-an-app/interact-with-warden-modules/interact-with-x-warden/manage-spaces.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ This article explains how to use `x/warden` to manage [Spaces](/learn/glossary#s
1313
To understand how to set up and deploy your project, see [Get started](../get-started.md).
1414

1515
:::tip
16-
For an overview of `x/warden` functions, refer to [Precompiles: x/warden](../../precompiles/x-warden#spaces)
16+
- For an overview of `x/warden` functions, refer to [Precompiles: x/warden](../../precompiles/x-warden#spaces).
17+
- The precompile address is `0x0000000000000000000000000000000000000900`.
1718
:::
1819

1920
## Create a new Space
@@ -22,11 +23,11 @@ To create a new Space, use the following code in your contract. It calls the [`n
2223

2324
```solidity
2425
function newSpace(
25-
uint64 approveAdminTemplateId,
26-
uint64 rejectAdminTemplateId,
27-
uint64 approveSignTemplateId,
28-
uint64 rejectSignTemplateId,
29-
address[] calldata additionalOwners
26+
uint64 approveAdminTemplateId,
27+
uint64 rejectAdminTemplateId,
28+
uint64 approveSignTemplateId,
29+
uint64 rejectSignTemplateId,
30+
address[] calldata additionalOwners
3031
) external returns (uint64 id);
3132
3233
contract wardenSpace {
@@ -311,13 +312,13 @@ contract SpaceQuery {
311312
warden = IWarden(WARDEN_ADDRESS);
312313
}
313314
314-
function getSpaceById(uint64 spaceId) external view returns (IWarden.Space memory) {
315-
return warden.spaceById(spaceId);
315+
function getSpaceById(uint64 id) external view returns (IWarden.Space memory) {
316+
return warden.spaceById(id);
316317
}
317318
}
318319
```
319320

320-
After deploying your contract, you can interact with it by calling the `spaceById()` function:
321+
After deploying your contract, you can interact with it by calling the `getSpaceById()` function:
321322

322323
```bash
323324
cast call $CONTRACT_ADDRESS "getSpaceById(uint64)" 1 --rpc-url $RPC_URL
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# Introduction
6+
7+
You can interact with [Warden Protocol modules](/category/warden-protocol-modules) in your EVM smart contract by calling [Warden precompiles](/category/precompiles).
8+
9+
To familiarize yourself with precompiles, take the following steps:
10+
11+
1. Deploy a simple EVM contract by following the [Get started](get-started) guide.
12+
3. After that, you can expand your contract code as shown in these subsections:
13+
- [Interact with x/warden](/category/interact-with-xwarden)
14+
- *Other modules: coming soon*
15+
4. For an overview of available functions, refer to the [Precompiles](/category/precompiles) section.
16+
17+
In this table, you can find all the resources you'll need to interact with each precompile:
18+
19+
| Functions | Code samples | Precompile address |
20+
| --------------------------------------------- | --------------------------------------------------------- |--------------------------------------------- |
21+
| [x/warden functions](../precompiles/x-warden) | [Interact with x/warden](/category/interact-with-xwarden) | `0x0000000000000000000000000000000000000900` |
22+
| [x/act functions](../precompiles/x-act) | *Coming soon* | `0x0000000000000000000000000000000000000901` |

0 commit comments

Comments
 (0)