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

[examples] Simple Javascript example for coin transfer #9

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

gregnazario
Copy link
Collaborator

@gregnazario gregnazario commented Oct 11, 2023

Description

The javascript example works and is able to do a coin transfer

Test Plan

pnpm test 

> js-test@1.0.0 test /opt/git/typescript-sdk/examples/javascript/simple_transfer
> node transfer.js

This example will create two accounts (Alice and Bob), fund them, and transfer between them.
=== Addresses ===

Alice's address is: 0xfb37999c6f6932c63902eea6aaa12f3e3ebd0d2b545fc1a9e87c2349d0b86a72
Bob's address is: 0x65dd44a57d1f3a0feab1d7e7b57e16488e0b1fc51a614f7affe1e5acf5b14ead

=== Funding accounts ===

Alice's fund transaction:  38ce8e546efeffa5e81df3af725b864753a84ecf3fb4863fd49dd5d81837edf8
Bob's fund transaction:  43c8bc1a3dc90f53ba4f1fe9cbf625b563e793d05af047b4db4ef9c294a2f3eb

=== Balances ===

Alice's balance is: 100000000
Bob's balance is: 100

=== Transfer transaction ===

Committed transaction: 0xac7302d52d6229a0ffa3d0bd73dfa38099da803ff855822f420b26ff687fb66a

=== Balances after transfer ===

Alice's balance is: 100000000
Bob's balance is: 100

Related Links

@gregnazario gregnazario requested a review from a team as a code owner October 11, 2023 01:34
heliuchuan
heliuchuan previously approved these changes Oct 11, 2023
Copy link
Contributor

@heliuchuan heliuchuan left a comment

Choose a reason for hiding this comment

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

lgtm

@heliuchuan heliuchuan requested a review from 0xmaayan October 11, 2023 04:17
@gregnazario gregnazario changed the title [examples] Get a semi-working javascript example Faucet and export improvements, as well as Javascript / Typescript simple examples Oct 11, 2023
@gregnazario gregnazario dismissed heliuchuan’s stale review October 11, 2023 15:51

Made some changes

@gregnazario gregnazario requested review from a team and heliuchuan October 11, 2023 15:51
@0xmaayan
Copy link
Collaborator

this is a huge PR, and has same fixes another PR has. I am a bit worried merging it now in regards to conflicts etc

@gregnazario
Copy link
Collaborator Author

this is a huge PR, and has same fixes another PR has. I am a bit worried merging it now in regards to conflicts etc

Sure, we can break it up into 3 PRs, but unfortunately one of them is still going to be big.

@gregnazario gregnazario changed the title Faucet and export improvements, as well as Javascript / Typescript simple examples Simple Javascript example for coin transfer Oct 11, 2023
@gregnazario gregnazario changed the title Simple Javascript example for coin transfer [examples] Simple Javascript example for coin transfer Oct 11, 2023
@gregnazario
Copy link
Collaborator Author

gregnazario commented Oct 11, 2023

this is a huge PR, and has same fixes another PR has. I am a bit worried merging it now in regards to conflicts etc

I've shrunk this down to just the javascript example now (github is slow today though)

Comment on lines +38 to +39
let alice = Account.generate({ scheme: 0 });
let bob = Account.generate({ scheme: 0 });
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Should we use SigningScheme enum here, instead of directly using 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The enum only exists in Typescript, so unfortunately, it didn't work! Had to use the number directly rather than the enum in Javascript.

It's been an interesting learning of Javascript vs Typescript when using them together

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We may want both the constants and the enum then (since I was the one who pushed to replace the constants with an enum)

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the enum as well, too bad for js i guess lol

Copy link
Collaborator

Choose a reason for hiding this comment

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

interesting.... we might want to have consts for js and enums for ts, we can probably build those "types" in separate files so if you use js import x.js

@gregnazario gregnazario force-pushed the javascript-example branch 4 times, most recently from aca5cbe to 8e1c2e7 Compare October 12, 2023 00:40
@gregnazario gregnazario enabled auto-merge (rebase) October 12, 2023 00:40
@gregnazario gregnazario disabled auto-merge October 12, 2023 00:43
@gregnazario gregnazario force-pushed the javascript-example branch 2 times, most recently from 30d400f to b3e922c Compare October 12, 2023 01:07
@gregnazario gregnazario enabled auto-merge (rebase) October 12, 2023 01:10
@gregnazario gregnazario merged commit f8e25b4 into main Oct 12, 2023
5 checks passed
@gregnazario gregnazario deleted the javascript-example branch October 12, 2023 01:14
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.

4 participants