-
Notifications
You must be signed in to change notification settings - Fork 146
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
Conversation
}, | ||
{ | ||
from: "/sdk-and-tools/sdk-js/sdk-js-cookbook", | ||
to: "/sdk-and-tools/sdk-js/sdk-js-cookbook-v12", |
There was a problem hiding this comment.
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.
- [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) |
There was a problem hiding this comment.
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.
title: Cookbook | ||
id: sdk-js-cookbook-v12 | ||
title: Cookbook (v12) | ||
pagination_next: sdk-and-tools/sdk-js/extending-sdk-js |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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**. |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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**. |
There was a problem hiding this comment.
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**.
There was a problem hiding this comment.
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). |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
// Legacy approach: | ||
|
||
const txLegacy = new Transaction({ | ||
data: new TransactionPayload("helloWorld"), | ||
gasLimit: 70000, | ||
sender: addressOfAlice, | ||
receiver: addressOfBob, | ||
value: "1000000000000000000", | ||
chainID: "D" | ||
}); | ||
|
||
txLegacy.setNonce(43); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
// The legacy approach of creating a "TransferTransactionsFactory": | ||
const legacyFactory = new TransferTransactionsFactory(new GasEstimator()); | ||
``` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() }); |
There was a problem hiding this comment.
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
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 ?
Which category (categories) does this pull request belong to?