Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Comp0te committed Nov 24, 2024
1 parent deb37a0 commit 65509c6
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 3 deletions.
86 changes: 83 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ npm install casper-js-sdk --save

## Base usage

- ### [Public and private keys](#public-and-private-keys)
- ### [RPC client](#rpc-client)
- ### [SSE](#sse)
- ### [Creating a transaction](#creating-a-transaction)
- ### [Creating a legacy deploy](#creating-a-legacy-deploy)
- ### [Creating and sending CSPR transfer deploy](#creating-and-sending-cspr-transfer-deploy)
- ### [Creating and sending Auction manager deploy](#creating-and-sending-auction-manager-deploy)

## Migration guides

### [v2 to v3](./migration-guide-v2-v3.md)

## Usage examples

### Public and private keys

Provides functionality for working with public and private key cryptography in Casper. [See more details here](src/types/keypair/README.md)
Expand Down Expand Up @@ -226,8 +240,74 @@ const result = await rpcClient.putDeploy(deploy);
console.log(`Deploy Hash: ${result.deployHash}`);
```

## Migration guides
### Creating and sending CSPR transfer deploy

### v2 to v3
Example of how to construct a CSPR transfer deploy and push it to the network:

In progress...
```ts
import {
HttpHandler,
RpcClient,
KeyAlgorithm,
PrivateKey,
makeCsprTransferDeploy
} from 'casper-js-sdk';

// get private key fromHex, fromPem or generate it
const privateKey = await PrivateKey.fromHex(
'privateKeyHex',
KeyAlgorithm.SECP256K1 // or KeyAlgorithm.ED25519, depends on your private key
);

const deploy = makeCsprTransferDeploy({
senderPublicKeyHex: privateKey.publicKey.toHex(),
recipientPublicKeyHex: '0123456789abcdef...',
transferAmount: '2500000000' // 2.5 CSPR
});

await deploy.sign(privateKey);

const rpcHandler = new HttpHandler('http://<Node Address>:7777/rpc');
const rpcClient = new RpcClient(rpcHandler);

const result = await rpcClient.putDeploy(deploy);

console.log(`Deploy Hash: ${result.deployHash}`);
```

### Creating and sending Auction manager deploy

Example of how to construct a Auction manager deploy (delegate/undelegate/redelegate CSPR) and push it to the network:

```ts
import {
HttpHandler,
RpcClient,
KeyAlgorithm,
PrivateKey,
makeAuctionManagerDeploy,
AuctionManagerEntryPoint
} from 'casper-js-sdk';

// get private key fromHex, fromPem or generate it
const privateKey = await PrivateKey.fromHex(
'privateKeyHex',
KeyAlgorithm.SECP256K1 // or KeyAlgorithm.ED25519, depends on your private key
);

const deploy = makeAuctionManagerDeploy({
contractEntryPoint: AuctionManagerEntryPoint.delegate,
delegatorPublicKeyHex: privateKey.publicKey.toHex(),
validatorPublicKeyHex: '0123456789awedef...',
amount: '500000000000' // 500 CSPR
});

await deploy.sign(privateKey);

const rpcHandler = new HttpHandler('http://<Node Address>:7777/rpc');
const rpcClient = new RpcClient(rpcHandler);

const result = await rpcClient.putDeploy(deploy);

console.log(`Deploy Hash: ${result.deployHash}`);
```
24 changes: 24 additions & 0 deletions migration-guide-v2-v3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# V2 to V3 Migration Guide

`Casper JS SDK V3` makes many **breaking changes** to the SDK behavior, effectively rewriting it from scratch.

The purpose of these changes is to improve and simplify the SDK, as well as to bring the Casper JS SDK to the same look and behavior as the Casper SDK in other languages.

Also added new functionality to work with the Casper 2.0 (Condor) update

## Changes

- `CasperServiceByJsonRPC` and `CasperClient` become [RpcClient](./src/rpc/rpc_client.ts). The `RpcClient` is much broader in functionality and is the main place to interact with the rpc. [See more details here](src/rpc/README.md)
- `EventStream` become [SseClient](./src/sse/client.ts). The `SseClient` is the main place to interact with Casper events. [See more details here](src/sse/README.md)
- `AsymmetricKey` was splitted into to classes [PrivateKey](./src/types/keypair/PrivateKey.ts)` and [PublicKey](./src/types/keypair/PublicKey.ts).
- `CLPublicKey` become [PublicKey](./src/types/keypair/PublicKey.ts).
- `RuntimeArgs` become [Args](./src/types/Args.ts)
- Most classes that previously was in `src/lib` folder was redesigned and you can find them in `src/types` folder
- Functionality for deploy creation `DeployUtil` become [Deploy](./src/types/Deploy.ts) class with static methods. [See how to create Deploy here](./README.md#creating-a-legacy-deploy-1)
- Instead of `CLValueBuilder` it's possible to use `CLValue` constructors. For example `CLValueBuilder.bool(false)` become `new CLValueBool(false)`
- `CasperHDKey`now deprecated and out of scope of this lib. You can use `@scure/bip39` lib to achieve same result as in previous SKD version.
- Injected `CasperWallet` provider now out of scope of this lib.

## Casper 2.0 (Condor)

In progress...

0 comments on commit 65509c6

Please sign in to comment.