Skip to content

Commit 03597ba

Browse files
authored
Merge pull request #114 from ssvlabs/update-code-snippets
Update code examples
2 parents efe4fe4 + 3040e71 commit 03597ba

File tree

8 files changed

+653
-228
lines changed

8 files changed

+653
-228
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
sidebar_position: 8
3+
---
4+
5+
# Deposit SSV
6+
7+
This page shows how to programmatically deposit SSV to a cluster on the SSV network. This executes the contract call to the SSV smart contract to deposit SSV to the cluster.
8+
9+
### Deposit SSV
10+
11+
```typescript
12+
import { parseEther } from 'viem';
13+
14+
try {
15+
const txnReceipt = await sdk.clusters.deposit({
16+
args: {
17+
id: "ee8881d3c979203025996773ef8a13cb4aac57076e22638dd6ed9b17adcdabfc",
18+
amount: parseEther('30'),
19+
},
20+
}, {
21+
approve: true, // Automatically triggers token approval transaction if the allowance is lower than the deposit amount
22+
}).then(tx => tx.wait());
23+
24+
console.log('Transaction receipt:', txnReceipt);
25+
} catch (error) {
26+
console.error('Failed to deposit SSV:', error);
27+
}
28+
```
29+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
sidebar_position: 7
3+
---
4+
5+
# Exit Validator
6+
7+
This page shows how to programmatically exit a validator from the SSV network. This prompts SSV nodes to sign a voluntary exit of the validator.
8+
9+
### Exit Validator
10+
11+
```typescript
12+
try {
13+
const txnReceipt = await sdk.clusters.exitValidators({
14+
args: {
15+
publicKeys: ["0xA4831B989972605A62141a667578d742927Cbef9", "0xA4831B989972605A62141a667578d742927Cbef8"],
16+
operatorIds: [1, 2, 3, 4],
17+
},
18+
}).then(tx => tx.wait());
19+
20+
console.log('Transaction receipt:', txnReceipt);
21+
} catch (error) {
22+
console.error('Failed to exit validators:', error);
23+
}
24+
```
25+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
sidebar_position: 6
3+
---
4+
5+
# Remove Validator
6+
7+
This page shows how to programmatically remove validators from a cluster on the SSV network.
8+
9+
### Remove Validator
10+
11+
```typescript
12+
try {
13+
const txnReceipt = await sdk.clusters.removeValidators({
14+
args: {
15+
id: "ee8881d3c979203025996773ef8a13cb4aac57076e22638dd6ed9b17adcdabfc",
16+
publicKeys: [
17+
"0x820fd0519c75f74c8be9f21f185406919721dad0c624464538e2eaa323d77d3eb3ef27a039e8779de6cfa649a5484e86",
18+
"0x820fd0519c75f74c8be9f21f185406919721dad0c624464538e2eaa323d77d3eb3ef27a039e8779de6cfa649a5484e87"
19+
],
20+
},
21+
}).then(tx => tx.wait());
22+
23+
console.log('Transaction receipt:', txnReceipt);
24+
} catch (error) {
25+
console.error('Failed to remove validators:', error);
26+
}
27+
```
28+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
sidebar_position: 9
3+
---
4+
5+
# Withdraw SSV
6+
7+
This page shows how to programmatically withdraw SSV from a cluster on the SSV network.
8+
9+
### Withdraw SSV
10+
11+
```typescript
12+
import { parseEther } from 'viem';
13+
14+
try {
15+
const txnReceipt = await sdk.clusters.withdraw({
16+
args: {
17+
id: "ee8881d3c979203025996773ef8a13cb4aac57076e22638dd6ed9b17adcdabfc",
18+
amount: parseEther('30'),
19+
},
20+
}).then(tx => tx.wait());
21+
22+
console.log('Transaction receipt:', txnReceipt);
23+
} catch (error) {
24+
console.error('Failed to withdraw SSV:', error);
25+
}
26+
```
27+

0 commit comments

Comments
 (0)