Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookbooks sdk-js: versioned #851

Merged
merged 8 commits into from
Mar 27, 2024
Merged

Cookbooks sdk-js: versioned #851

merged 8 commits into from
Mar 27, 2024

Conversation

andreibancioiu
Copy link
Contributor

Description of the pull request (what is new / what has changed)

Separate pages / cookbooks for previous, current and next versions of SDK-JS.

Did you test the changes locally ?

  • yes
  • no

Which category (categories) does this pull request belong to?

  • document new feature
  • update documentation that is not relevant anymore
  • add examples or more information about a component
  • fix grammar issues
  • other

@andreibancioiu andreibancioiu changed the base branch from main to development March 26, 2024 14:49
@andreibancioiu andreibancioiu self-assigned this Mar 26, 2024
@andreibancioiu andreibancioiu marked this pull request as ready for review March 26, 2024 14:49
@andreibancioiu andreibancioiu changed the title Cookbooks js more Cookbooks sdk-js: more versions (previous, current, next) Mar 26, 2024
@andreibancioiu andreibancioiu changed the title Cookbooks sdk-js: more versions (previous, current, next) Cookbooks sdk-js: versioned Mar 27, 2024
},
{
from: "/sdk-and-tools/sdk-js/sdk-js-cookbook",
to: "/sdk-and-tools/sdk-js/sdk-js-cookbook-v12",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When v13 is released, we will adjust this.

Comment on lines +15 to +16
- [Cookbook v12 **(stable, current version)**](/sdk-and-tools/sdk-js/sdk-js-cookbook-v12)
- [Cookbook v13 **(unstable, upcoming version)**](/sdk-and-tools/sdk-js/sdk-js-cookbook-v13)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When v13 is released, we will adjust this page.

bogdan-rosianu
bogdan-rosianu previously approved these changes Mar 27, 2024
title: Cookbook
id: sdk-js-cookbook-v12
title: Cookbook (v12)
pagination_next: sdk-and-tools/sdk-js/extending-sdk-js
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When v13 is released, we will adjust this.

---
id: sdk-js-cookbook-v13
title: Cookbook (v13)
pagination_next: null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When v13 is released, we will adjust this.

{
label: "Cookbook",
type: "doc",
id: "sdk-and-tools/sdk-js/sdk-js-cookbook-v12",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When v13 is released, we will adjust this.

@@ -325,11 +325,11 @@ const config = {
},
{
from: "/sdk-and-tools/erdjs/erdjs-cookbook",
to: "/sdk-and-tools/sdk-js/sdk-js-cookbook",
to: "/sdk-and-tools/sdk-js/sdk-js-cookbook-versions",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old link (erdjs) goes to the versions page.

title: Cookbook
id: sdk-js-cookbook-v12
title: Cookbook (v12)
pagination_next: sdk-and-tools/sdk-js/extending-sdk-js
---

[comment]: # (mx-abstract)

This page will guide you through the process of handling common tasks using **sdk-js**.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add something like:

This is an older version of sdk-js, please use the latest one (v13).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, but we'll write this only after releasing v13 as a stable release.


[comment]: # (mx-abstract)

This page will guide you through the process of handling common tasks using **upcoming versions** of **sdk-js**.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional] Can also be:

This page will guide you through the process of handling common tasks using **the latest version** of **sdk-js**.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, but we'll write this only after releasing v13 as a stable release.

This page will guide you through the process of handling common tasks using **upcoming versions** of **sdk-js**.

:::important
This cookbook makes use of `sdk-js v13`. In order to migrate from `sdk-js v12.x` to `sdk-js v13`, please also follow [the migration guide](/sdk-and-tools/sdk-js/sdk-js-migration-guides).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also redirect to the github migration issue.

Copy link
Contributor Author

@andreibancioiu andreibancioiu Mar 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Now redirecting to multiversx/mx-sdk-js-core#392.

// Recommended approach:

const tx = new Transaction({
data: new TextEncoder().encode("food for cats"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps use Buffer to stay consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines 115 to 126
// Legacy approach:

const txLegacy = new Transaction({
data: new TransactionPayload("helloWorld"),
gasLimit: 70000,
sender: addressOfAlice,
receiver: addressOfBob,
value: "1000000000000000000",
chainID: "D"
});

txLegacy.setNonce(43);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest we drop the legacy way of doing things since we still have the cookbook for v12 and we want people to do things the new way. By doing things the new way people also skip the breaking changes when we eventually drop the support for the old way. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, good point. Removing legacy approaches from v13 cookbook.

txLegacy.setNonce(43);
```

### Broadcast using a network provider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps also sign the transaction using js-wallet, so the user has the complete flow. Just an idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, added.

:::important
Note that the transactions **must be signed before being broadcasted**.
On the front-end, signing can be achieved using a signing provider.
On this purpose, **we recommend using [sdk-dapp](https://github.com/multiversx/mx-sdk-dapp)** instead of integrating the signing providers on your own.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redirect to the sdk-dapp docs page instead of the GH repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


Generally speaking, in order to create transactions that transfer native tokens or ESDT tokens, one should use the `TransferTransactionsFactory` class.

::note
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs one more :. Should be :::note.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines 207 to 209
// The legacy approach of creating a "TransferTransactionsFactory":
const legacyFactory = new TransferTransactionsFactory(new GasEstimator());
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you agree, same comment as above, drop the legacy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


// The new approach of creating a "TransferTransactionsFactory":
const factoryConfig = new TransactionsFactoryConfig({ chainID: "D" });
const factory = new TransferTransactionsFactory({ config: factoryConfig, tokenComputer: new TokenComputer() });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TokenComputer is no longer needed on the constructor

@andreibancioiu andreibancioiu merged commit ac4d1cd into development Mar 27, 2024
2 checks passed
@andreibancioiu andreibancioiu deleted the cookbooks-js-more branch March 27, 2024 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants