Skip to content

Commit b2f130e

Browse files
authored
Merge pull request #91 from casper-network/fix/CD-98/txn-page-errors
[CD-98] Update Condor Transactions page
2 parents 9e17e76 + 30105f6 commit b2f130e

File tree

2 files changed

+165
-16
lines changed

2 files changed

+165
-16
lines changed

condor/images/transfer_example.png

102 KB
Loading

condor/transactions.md

Lines changed: 165 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
title: Transactions in Casper 2.0
33
description: A discussion of the new Transaction data type
44
slug: transactions
5-
date: 2024-10-03T18:00
6-
authors: [ asladeofgreen ]
5+
date: 2025-07-10T18:00
6+
authors: [ asladeofgreen, melpadden, devendranm ]
77
tags: [v2, smartcontracts]
88
hide_table_of_contents: false
99
---
@@ -18,28 +18,177 @@ In this article we will examine user transactions (previously called deploys).
1818

1919
Transactions encapsulate user intents. For example, if Alice intends to transfer CSPR to Bob, she uses software (e.g. a wallet) to construct and sign a transaction that is subsequently dispatched to a trusted node for processing by the network.
2020

21-
Transactions may be either 'native' or 'custom':
21+
Transactions may be either 'native' or 'WASM':
2222

23-
- Native transactions are those that interact with system contracts such as mint and/or auction. They do not require any WASM payload to be constructed, are normally compact in size, and are processed directly on the metal, i.e. host-side.
23+
- Native transactions are those that interact with system contracts such as `mint` and/or `auction`. They do not require any Web Assembly(WASM) payload to be constructed, are normally compact in size, and are processed directly on the metal, i.e. host-side.
2424

25-
- Custom transactions are those that interact with the system via either on-chain smart contracts or in-line session logic. All such interactions are based upon user-defined WASM binaries, and are executed within one of the node's supported virtual machines.
25+
- Web Assembly(WASM) transactions are those that interact with the system via either on-chain smart contracts or session logic. All such interactions are based upon user-defined WASM binaries, and are executed within one of the node's supported virtual machines.
2626

27-
In Casper 1.0 there was a single native transaction type (Transfer), and a set of custom transaction types (ContractByHash, ContractByHashVersioned, ContractByName, ContractByNameVersioned, ContractBytes). In Casper 2.0 the set of both native & custome transaction types have been expanded.
27+
In Casper 1.0 there was a single native transaction type (Transfer), and a set of WASM based transaction types (ContractByHash, ContractByHashVersioned, ContractByName, ContractByNameVersioned, ContractBytes). In Casper 2.0 the set of both native & WASM transaction types have been expanded.
2828

2929
Casper 2.0 Native Transaction Types:
3030

31-
- System.Mint.Transfer
32-
- System.Mint.Burn
33-
- System.Auction.Bid.Submit
34-
- System.Auction.Bid.Withdraw
35-
- System.Auction.Delegation.Redelegate
36-
- System.Auction.Delegation.Submit
37-
- System.Auction.Delegation.Withdraw
38-
- System.Auction.Staking.Submit
39-
- System.Auction.Staking.Withdraw
31+
|Type|Description|
32+
|--------|---------------------------------|
33+
| `add-bid` | To create a bid purse or or increase an existing bidder's bid amount |
34+
| `activate-bid` | To reactivate an inactive bid |
35+
| `withdraw-bid` | Used to decrease a validator's stake or remove their bid completely if the remaining stake is below the minimum required amount |
36+
| `delegate` | Used to add a new delegator or increase an existing delegator's stake |
37+
| `undelegate` | To reduce a delegator's stake or remove the delegator if the remaining stake is zero |
38+
| `redelegate` | To reduce a delegator's stake or remove the delegator if the remaining stake is zero. After the unbonding delay, it will automatically delegate to a new validator |
39+
| `transfer` | Used to reference motes from a source purse to a target purse |
4040

4141
Not all work is identical, e.g. a base token (cspr) transfer differs from a smart contract execution.
4242

4343
Casper 1.0 supported a set of 6 transaction types, in Casper 2.0 the set is both refined and expanded.
4444

45-
The Transaction stat type has a number of changes from its predecessor, the Deploy. For a detailed discussion of these differences you can see the casper documentation of this discussion of the JSON schema.
45+
The Transaction type has a number of changes from its predecessor, the Deploy.
46+
47+
### Deploys and Transactions
48+
49+
The Deploy model is deprecated as of Casper 2.0, and support will be removed entirely in a future major release. However, Casper 2.0 will continue to accept valid Deploys and will attempt to execute them. For more details on Transactions, please refer to the Documentation section [here](https://docs.casper.network/concepts/transactions).
50+
51+
## How to create a transaction
52+
53+
A transaction, such as transferring CSPR tokens from one user's purse to another, can be created and sent to the Casper Network for processing using any of three methods:
54+
55+
1. CSPR.Live
56+
2. SDK [e.g JavaScript/TypeScript SDK]
57+
3. Casper Client
58+
59+
### 1. CSPR.Live
60+
61+
You can transfer Casper tokens (CSPR) using any block explorer built to explore the Casper blockchain. The Wallet feature on these block explorers enables transfers to another user's purse, delegate stake, or undelegate stake.
62+
63+
[CSPR.Live](https://cspr.live/) is the main and recommended Casper block explorer. For detailed guidance, the [**Transferring Tokens**](https://docs.casper.network/users/token-transfer#transferring-tokens-1) page in the **Users** section of the documentation provides step-by-step instructions on how to transfer CSPR tokens using CSPR.live.
64+
65+
### 2. SDK
66+
67+
The following example demonstrates how to create and execute a native CSPR token transfer using the JavaScript SDK. This walkthrough shows the complete process of constructing, signing, and submitting a transaction to the Casper Network.
68+
69+
#### 2.1. Initialize RPC client with network endpoint
70+
71+
This is to establish connection to a Casper node endpoint for network communication.
72+
73+
```js
74+
const rpcHandler = new HttpHandler(ENDPOINT);
75+
const rpcClient = new RpcClient(rpcHandler);
76+
```
77+
78+
#### 2.2. Load sender's private key securely
79+
80+
This is to load the sender's private key from a secure file location using Ed25519 cryptography.
81+
82+
```js
83+
const privateKey = getPrivateKey_ed25519(PRIVATE_KEY_PATH);
84+
```
85+
86+
#### 2.3. Build transaction
87+
88+
Build transaction using `NativeTransferBuilder` with:
89+
- Sender and recipient addresses
90+
- Transfer amount (in motes: 1 CSPR = 1,000,000,000 motes)
91+
- Unique transaction ID
92+
- Network chain name
93+
- Gas payment amount
94+
95+
**NOTE:** All amounts must be specified in motes (smallest CSPR unit)
96+
97+
```js
98+
const transaction = new NativeTransferBuilder()
99+
.from(privateKey.publicKey) // Sender's public key
100+
.target(PublicKey.fromHex('015ae...')) // Recipient's public key
101+
.amount('2500000000') // 2.5 CSPR in motes
102+
.id(Date.now()) // Unique transaction ID
103+
.chainName(NETWORKNAME) // Network identifier
104+
.payment(100_000_000) // Gas fee (0.1 CSPR)
105+
.build();
106+
```
107+
108+
109+
#### 2.4. Sign transaction with private key
110+
111+
The transaction built in the previous step is signed using the private key;
112+
113+
```js
114+
transaction.sign(privateKey);
115+
```
116+
117+
#### 2.5. Submit to network
118+
119+
In this step, the constructed transaction is submitted to the network;
120+
121+
```js
122+
try {
123+
const result = await rpcClient.putTransaction(transaction);
124+
console.log(Transaction Hash: ${result.transactionHash});
125+
} catch (e) {
126+
console.error(e);
127+
}
128+
```
129+
130+
131+
#### 2.6. Receive transaction hash for tracking
132+
133+
A transaction hash will be returned , which the user can use it to verify the transaction in the Block Explorer like CSPR.Live
134+
135+
Below is a screenshot of an example Transfer [transaction](https://cspr.live/transaction/7ef02f29e9589b971615e79bb2325b1bffff144ede2137bb9366497b9fc9afb5) on the Mainnet;
136+
137+
![CSPR Transfer example](./images/transfer_example.png)
138+
139+
In this example transaction `7ef02f29e9589b971615e79bb2325b1bffff144ede2137bb9366497b9fc9afb5`, 49, 999.60 CSPR has been transferred from `020396133b3bbbfcf7d1961390f9449e2de5813523180376df361cb31a1ca965b576` to `020312d2d4c4cac436b4c9bd0dc7eba4d129bf5eb05e02f731f7a89221d2fde970c1`
140+
141+
The "Raw Data" will give more details about the transaction.
142+
143+
### 3. Casper Client
144+
145+
A transaction can be initiated by using casper-client-rs CLI. Example V1 (2.0.0) and legacy transfers are given below with the clarity;
146+
147+
#### V1
148+
149+
```sh
150+
# Casper CLI command to transfer CSPR tokens
151+
casper-client put-transaction transfer \
152+
--target 010068920746ecf5870e18911ee1fc5db975e0e97fffcbbf52f5045ad6c9838d2f \
153+
# Recipient's public key (hexadecimal format)
154+
--transfer-amount 2500000000 \ # Amount to transfer: 2.5 CSPR (in motes)
155+
--chain-name integration-test \ # Network chain identifier , integration-test in this example
156+
--gas-price-tolerance 1 \ # Gas price tolerance (multiplier)
157+
--secret-key path/to/secret_key.pem \ # Path to sender's private key file
158+
--payment-amount 100000000 \ # Gas fee: 0.1 CSPR (in motes)
159+
--standard-payment true \ # Use standard payment logic
160+
-n http://node.integration.casper.network:7777/rpc # Network RPC endpoint URL
161+
```
162+
163+
164+
#### Legacy
165+
166+
```sh
167+
# Casper CLI command to transfer CSPR tokens (legacy)
168+
169+
casper-client transfer \
170+
--amount 2500000000 \ # Amount to transfer: 2.5 CSPR (in motes)
171+
--target-account 010068920746ecf5870e18911ee1fc5db975e0e97fffcbbf52f5045ad6c9838d2f \ #Recipient's public key (hexadecimal format)
172+
--transfer-id 123 \ #Unique transfer identifier (prevents replay attacks)
173+
--secret-key path/to/secret_key.pem \
174+
#Path to sender's private key file (PEM format)
175+
--chain-name integration-test \ #Network chain identifier , integration-test in this example
176+
--payment-amount 100000000 \ #Gas fee: 0.1 CSPR (in motes)
177+
-n http://node.integration.casper.network:7777/rpc
178+
# Network RPC endpoint URL
179+
```
180+
181+
182+
### Delegate and Undelegate Tokens
183+
184+
CSPR token holders can earn rewards and participate in the protocol through a mechanism called delegation or [staking](https://docs.casper.network/concepts/economics/staking).
185+
186+
If a user wants to undelegate tokens from their chosen validator, they can do so at any time.
187+
188+
#### Delegate Tokens
189+
190+
The tutorial [**Delegating Tokens with a Block Explorer**](https://docs.casper.network/users/delegate-ui) covers in detail how a user can delegate their tokens.
191+
192+
#### Undelegate Tokens
193+
194+
In order to undelegate their already delegated token, user can follow the step-by-step guide in the [**Undelegating Tokens**](https://docs.casper.network/users/undelegate-ui) section.

0 commit comments

Comments
 (0)