-
Notifications
You must be signed in to change notification settings - Fork 87
feat: generate TypeScript bindings for Soroban smart contracts #517
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
Closed
Josue19-08
wants to merge
4
commits into
boundlessfi:main
from
Josue19-08:feat/soroban-contract-bindings
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e427857
feat: generate TypeScript bindings for Soroban smart contracts
Josue19-08 dfbf74d
chore: remove generated npm package scaffolding from contract bindings
Josue19-08 309eb6c
chore: restore generated npm package scaffolding for contract bindings
Josue19-08 0fbed03
fix: address CodeRabbit review comments on Soroban contract bindings
Josue19-08 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| node_modules/ | ||
| out/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # bounty-registry JS | ||
|
|
||
| JS library for interacting with [Soroban](https://soroban.stellar.org/) smart contract `bounty-registry` via Soroban RPC. | ||
|
|
||
| This library was automatically generated by Soroban CLI using a command similar to: | ||
|
|
||
| ```bash | ||
| soroban contract bindings ts \ | ||
| --rpc-url https://soroban-testnet.stellar.org:443 \ | ||
| --network-passphrase "Test SDF Network ; September 2015" \ | ||
| --contract-id CBWXIV3DERH4GKADOTEEI2QADGZAMMJT4T2B5LFVZULGHEP5BACK2TLY \ | ||
| --output-dir ./path/to/bounty-registry | ||
| ``` | ||
|
|
||
| The network passphrase and contract ID are exported from [index.ts](./src/index.ts) in the `networks` constant. If you are the one who generated this library and you know that this contract is also deployed to other networks, feel free to update `networks` with other valid options. This will help your contract consumers use this library more easily. | ||
|
|
||
| # To publish or not to publish | ||
|
|
||
| This library is suitable for publishing to NPM. You can publish it to NPM using the `npm publish` command. | ||
|
|
||
| But you don't need to publish this library to NPM to use it. You can add it to your project's `package.json` using a file path: | ||
|
|
||
| ```json | ||
| "dependencies": { | ||
| "bounty-registry": "./path/to/this/folder" | ||
| } | ||
| ``` | ||
|
|
||
| However, we've actually encountered [frustration](https://github.com/stellar/soroban-example-dapp/pull/117#discussion_r1232873560) using local libraries with NPM in this way. Though it seems a bit messy, we suggest generating the library directly to your `node_modules` folder automatically after each install by using a `postinstall` script. We've had the least trouble with this approach. NPM will automatically remove what it sees as erroneous directories during the `install` step, and then regenerate them when it gets to your `postinstall` step, which will keep the library up-to-date with your contract. | ||
|
|
||
| ```json | ||
| "scripts": { | ||
| "postinstall": "soroban contract bindings ts --rpc-url https://soroban-testnet.stellar.org:443 --network-passphrase \"Test SDF Network ; September 2015\" --id CBWXIV3DERH4GKADOTEEI2QADGZAMMJT4T2B5LFVZULGHEP5BACK2TLY --name bounty-registry" | ||
| } | ||
| ``` | ||
|
|
||
| Obviously you need to adjust the above command based on the actual command you used to generate the library. | ||
|
|
||
| # Use it | ||
|
|
||
| Now that you have your library up-to-date and added to your project, you can import it in a file and see inline documentation for all of its exported methods: | ||
|
|
||
| ```js | ||
| import { Contract, networks } from "bounty-registry" | ||
|
|
||
| const contract = new Contract({ | ||
| ...networks.futurenet, // for example; check which networks this library exports | ||
| rpcUrl: '...', // use your own, or find one for testing at https://soroban.stellar.org/docs/reference/rpc#public-rpc-providers | ||
| }) | ||
|
|
||
| contract.| | ||
| ``` | ||
|
|
||
| As long as your editor is configured to show JavaScript/TypeScript documentation, you can pause your typing at that `|` to get a list of all exports and inline-documentation for each. It exports a separate [async](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) function for each method in the smart contract, with documentation for each generated from the comments the contract's author included in the original source code. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "version": "0.0.0", | ||
| "name": "bounty-registry", | ||
| "type": "module", | ||
| "exports": "./dist/index.js", | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "typings": "dist/index.d.ts", | ||
| "scripts": { | ||
| "build": "tsc" | ||
| }, | ||
| "dependencies": { | ||
| "@stellar/stellar-sdk": "^14.5.0", | ||
| "buffer": "6.0.3" | ||
| }, | ||
| "devDependencies": { | ||
| "typescript": "^5.6.2" | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.