Skip to content

Commit fdc5074

Browse files
fadeevhernan-clich
andauthored
Staking tutorial (#719)
Co-authored-by: Hernan Clich <62221379+hernan-clich@users.noreply.github.com>
1 parent c5c7959 commit fdc5074

File tree

2 files changed

+190
-0
lines changed

2 files changed

+190
-0
lines changed

src/pages/developers/tutorials/_meta.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,10 @@
4343
"title": "Calls to Sui",
4444
"readTime": "60 min",
4545
"description": "Withdraw assets and call contracts on Sui"
46+
},
47+
"staking": {
48+
"title": "Staking",
49+
"readTime": "10 min",
50+
"description": "Delegate and undelegate ZETA from EVM"
4651
}
4752
}
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
ZetaChain is a proof-of-stake blockchain built with the Cosmos SDK, secured by
2+
validators who stake the native ZETA token. Delegators (regular users) can
3+
participate in securing the network by staking their ZETA with validators and,
4+
in return, earn rewards. Because ZetaChain is also an EVM environment, smart
5+
contracts can access Cosmos staking functionality directly through a special
6+
staking precompile. This allows contracts, scripts, and frontends to delegate,
7+
undelegate, claim rewards, and more, all using familiar EVM tooling.
8+
9+
In this tutorial, we’ll use Foundry (`cast`) and curl to interact with the
10+
staking precompile. The same functions can also be called from Solidity
11+
contracts or web frontends.
12+
13+
- Precompile address: `0x0000000000000000000000000000000000000800`
14+
- Documentation: [Staking
15+
Precompile](https://evm.cosmos.network/v0.4.x/documentation/smart-contracts/precompiles/staking)
16+
- Interface:
17+
[StakingI.sol](https://github.com/cosmos/evm/blob/v0.4.0/precompiles/staking/StakingI.sol)
18+
19+
### Prerequisites
20+
21+
- [Foundry](https://getfoundry.sh/) (includes `cast`)
22+
- `jq` for JSON processing
23+
- A funded testnet wallet private key with ZETA
24+
25+
### Quick environment setup
26+
27+
```bash
28+
export RPC_URL="https://zetachain-athens-evm.blockpi.network/v1/rpc/public"
29+
export PRIVATE_KEY="YOUR_PRIVATE_KEY_HEX"
30+
31+
cast wallet address $PRIVATE_KEY
32+
cast balance --rpc-url "$RPC_URL" $(cast wallet address $PRIVATE_KEY)
33+
34+
export STAKING_PRECOMPILE=0x0000000000000000000000000000000000000800
35+
```
36+
37+
## Listing Validators
38+
39+
Before delegating, you need to know which validators are available on ZetaChain.
40+
Each validator has an operator address (`zetavaloper...`) that you’ll delegate
41+
to.
42+
43+
The Cosmos SDK exposes a REST API (LCD) that lists validators. For bonded
44+
validators (actively participating in consensus):
45+
46+
```bash
47+
curl -s \
48+
"https://zetachain-athens.blockpi.network/lcd/v1/public/cosmos/staking/v1beta1/validators?status=BOND_STATUS_BONDED&pagination.limit=1000" \
49+
| jq -r '.validators[] | [ .operator_address, (.description.moniker) ] | @tsv'
50+
```
51+
52+
Example output:
53+
54+
```
55+
zetavaloper1qumrwnz9x2emzd5yjylp8pf9w2wh3my0gag27y LiveRaveN
56+
zetavaloper1p3emgemv8q0fmtw70kfzwecmcvyd9ztqlzudwn RockX
57+
zetavaloper1ymnrwg9e3xr9xkw42ygzjx34dyvwvtc24ct0t5 validator1-us-west-2
58+
zetavaloper1xkddnhcdy5j4auzefjqkt3kp56t6vq7sm5xlga BlockPI
59+
...
60+
```
61+
62+
This is the easiest way to fetch validator operator addresses for staking.
63+
64+
You can also call the precompile’s `validators` function directly from a
65+
contract or frontend if you prefer to fetch the data inside the EVM.
66+
67+
Validators are also available on [ZetaChain
68+
explorers](https://testnet.zetachain.exploreme.pro/validators).
69+
70+
## Delegating
71+
72+
Delegation sends your native ZETA to a validator to help secure the network and
73+
earn staking rewards. With the staking precompile, you can do this straight from
74+
EVM tools.
75+
76+
- `amount` is in wei (1 ZETA = `1e18` wei).
77+
- Send the same amount in `--value`, because delegation consumes native ZETA.
78+
79+
```bash
80+
cast send $STAKING_PRECOMPILE \
81+
"delegate(address,string,uint256)" \
82+
$(cast wallet address $PRIVATE_KEY) \
83+
"zetavaloper1ymnrwg9e3xr9xkw42ygzjx34dyvwvtc24ct0t5" \
84+
1000000000000000000 \
85+
--rpc-url $RPC_URL \
86+
--private-key $PRIVATE_KEY
87+
```
88+
89+
This transaction bonds 1 ZETA to the validator.
90+
91+
### Verify your delegation
92+
93+
You can check how much ZETA you’ve delegated to a validator using the
94+
`delegation` function. It returns `(uint256 shares, (string denom, uint256 amount))`.
95+
96+
```bash
97+
cast call $STAKING_PRECOMPILE \
98+
"delegation(address,string)(uint256,(string,uint256))" \
99+
$(cast wallet address $PRIVATE_KEY) \
100+
"zetavaloper1ymnrwg9e3xr9xkw42ygzjx34dyvwvtc24ct0t5" \
101+
--rpc-url $RPC_URL
102+
```
103+
104+
Example output:
105+
106+
```
107+
(1000000000000000000, (azeta, 1000000000000000000))
108+
```
109+
110+
- shares: staking shares in the validator’s pool
111+
- balance: your delegated amount in wei (denom is `azeta`)
112+
113+
## Undelegating
114+
115+
Undelegation starts the unbonding period: your staked ZETA stops earning rewards
116+
and becomes withdrawable only after the unbonding time elapses. You can
117+
undelegate partially or fully.
118+
119+
- `amount` is in wei (1 ZETA = `1e18` wei).
120+
- Use the same validator operator address you delegated to.
121+
- Keep the `--value` equal to the `amount` for this precompile call pattern.
122+
123+
```bash
124+
cast send $STAKING_PRECOMPILE \
125+
"undelegate(address,string,uint256)" \
126+
$(cast wallet address $PRIVATE_KEY) \
127+
"zetavaloper1ymnrwg9e3xr9xkw42ygzjx34dyvwvtc24ct0t5" \
128+
1000000000000000000 \
129+
--rpc-url $RPC_URL \
130+
--private-key $PRIVATE_KEY
131+
```
132+
133+
This submits an undelegation of 1 ZETA from that validator.
134+
135+
### Verify the change
136+
137+
Your active delegation to that validator should decrease by the undelegated
138+
amount:
139+
140+
```bash
141+
cast call $STAKING_PRECOMPILE \
142+
"delegation(address,string)(uint256,(string,uint256))" \
143+
$(cast wallet address $PRIVATE_KEY) \
144+
"zetavaloper1ymnrwg9e3xr9xkw42ygzjx34dyvwvtc24ct0t5" \
145+
--rpc-url $RPC_URL
146+
```
147+
148+
Example (after undelegating 1 ZETA):
149+
150+
```
151+
(0, (azeta, 0))
152+
```
153+
154+
or, if partially undelegated, a lower balance than before.
155+
156+
### Notes
157+
158+
- Unbonding period applies. The undelegated amount is locked until the unbonding
159+
time completes. After that, it becomes liquid ZETA in your account.
160+
- You can submit multiple undelegations (they create separate unbonding
161+
entries).
162+
- Trying to undelegate more than your active delegation will revert.
163+
164+
## Conclusion
165+
166+
By using the staking precompile, you can interact with ZetaChain’s
167+
proof-of-stake system directly from the EVM. This means you don’t need separate
168+
Cosmos tooling to delegate, undelegate, or query validator data, everything can
169+
be done with the same `cast` commands, Solidity contracts, or frontend apps you
170+
already use.
171+
172+
You can also build universal contracts that handle incoming calls from connected
173+
chains and stake ZETA on behalf of users. This opens the door to powerful
174+
cross-chain apps such as:
175+
176+
- Protocols that automatically stake rewards or idle balances from multiple
177+
chains
178+
- Yield strategies that combine cross-chain liquidity with staking
179+
- Apps that give users a single interface to manage delegations without leaving
180+
their home chain
181+
182+
Staking is one of the simplest but most important features for securing the
183+
network and earning rewards. From here, you can explore more advanced precompile
184+
functions such as redelegation, querying unbonding entries, and reward
185+
distribution.

0 commit comments

Comments
 (0)