Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ src/data-import/data/users.csv

.vercel
.tool-versions

contract/target
contract/.vars
.soroban
Binary file modified .yarn/install-state.gz
Binary file not shown.
2 changes: 2 additions & 0 deletions contract-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
out/
54 changes: 54 additions & 0 deletions contract-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# contract-client JS

JS library for interacting with [Soroban](https://soroban.stellar.org/) smart contract `contract-client` 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 CC5ELPSQFQMJ75XUPJARIODNA7UIH4RS36N37BAV4SVEBEDN4PJYVL5E \
--output-dir ./path/to/contract-client
```

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": {
"contract-client": "./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 CC5ELPSQFQMJ75XUPJARIODNA7UIH4RS36N37BAV4SVEBEDN4PJYVL5E --name contract-client"
}
```

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 "contract-client"

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.
134 changes: 134 additions & 0 deletions contract-client/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { AssembledTransaction, Client as ContractClient, ClientOptions as ContractClientOptions } from '@stellar/stellar-sdk/contract';
import type { i128 } from '@stellar/stellar-sdk/contract';
export * from '@stellar/stellar-sdk';
export * as contract from '@stellar/stellar-sdk/contract';
export * as rpc from '@stellar/stellar-sdk/rpc';
export declare const networks: {
readonly testnet: {
readonly networkPassphrase: "Test SDF Network ; September 2015";
readonly contractId: "CC5ELPSQFQMJ75XUPJARIODNA7UIH4RS36N37BAV4SVEBEDN4PJYVL5E";
};
};
export type DataKey = {
tag: "Index";
values: void;
} | {
tag: "Entries";
values: readonly [string];
};
export interface Entry {
apr: i128;
equity_shares: Map<string, i128>;
escrow: i128;
ipfs_hash: string;
total_invested: i128;
}
export declare const Errors: {};
export interface Client {
/**
* Construct and simulate a set_entry transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
*/
set_entry: ({ entry }: {
entry: Entry;
}, options?: {
/**
* The fee to pay for the transaction. Default: BASE_FEE
*/
fee?: number;
/**
* The maximum amount of time to wait for the transaction to complete. Default: DEFAULT_TIMEOUT
*/
timeoutInSeconds?: number;
/**
* Whether to automatically simulate the transaction when constructing the AssembledTransaction. Default: true
*/
simulate?: boolean;
}) => Promise<AssembledTransaction<null>>;
/**
* Construct and simulate a get_entry transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
*/
get_entry: ({ ipfs_hash }: {
ipfs_hash: string;
}, options?: {
/**
* The fee to pay for the transaction. Default: BASE_FEE
*/
fee?: number;
/**
* The maximum amount of time to wait for the transaction to complete. Default: DEFAULT_TIMEOUT
*/
timeoutInSeconds?: number;
/**
* Whether to automatically simulate the transaction when constructing the AssembledTransaction. Default: true
*/
simulate?: boolean;
}) => Promise<AssembledTransaction<Entry>>;
/**
* Construct and simulate a invest transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
*/
invest: ({ user, ipfs_hash, amount }: {
user: string;
ipfs_hash: string;
amount: i128;
}, options?: {
/**
* The fee to pay for the transaction. Default: BASE_FEE
*/
fee?: number;
/**
* The maximum amount of time to wait for the transaction to complete. Default: DEFAULT_TIMEOUT
*/
timeoutInSeconds?: number;
/**
* Whether to automatically simulate the transaction when constructing the AssembledTransaction. Default: true
*/
simulate?: boolean;
}) => Promise<AssembledTransaction<null>>;
/**
* Construct and simulate a distribute_payout transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
*/
distribute_payout: ({ ipfs_hash }: {
ipfs_hash: string;
}, options?: {
/**
* The fee to pay for the transaction. Default: BASE_FEE
*/
fee?: number;
/**
* The maximum amount of time to wait for the transaction to complete. Default: DEFAULT_TIMEOUT
*/
timeoutInSeconds?: number;
/**
* Whether to automatically simulate the transaction when constructing the AssembledTransaction. Default: true
*/
simulate?: boolean;
}) => Promise<AssembledTransaction<null>>;
/**
* Construct and simulate a distribute_payouts transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object.
*/
distribute_payouts: (options?: {
/**
* The fee to pay for the transaction. Default: BASE_FEE
*/
fee?: number;
/**
* The maximum amount of time to wait for the transaction to complete. Default: DEFAULT_TIMEOUT
*/
timeoutInSeconds?: number;
/**
* Whether to automatically simulate the transaction when constructing the AssembledTransaction. Default: true
*/
simulate?: boolean;
}) => Promise<AssembledTransaction<null>>;
}
export declare class Client extends ContractClient {
readonly options: ContractClientOptions;
constructor(options: ContractClientOptions);
readonly fromJSON: {
set_entry: (json: string) => AssembledTransaction<null>;
get_entry: (json: string) => AssembledTransaction<Entry>;
invest: (json: string) => AssembledTransaction<null>;
distribute_payout: (json: string) => AssembledTransaction<null>;
distribute_payouts: (json: string) => AssembledTransaction<null>;
};
}
36 changes: 36 additions & 0 deletions contract-client/dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Buffer } from "buffer";
import { Client as ContractClient, Spec as ContractSpec, } from '@stellar/stellar-sdk/contract';
export * from '@stellar/stellar-sdk';
export * as contract from '@stellar/stellar-sdk/contract';
export * as rpc from '@stellar/stellar-sdk/rpc';
if (typeof window !== 'undefined') {
//@ts-ignore Buffer exists
window.Buffer = window.Buffer || Buffer;
}
export const networks = {
testnet: {
networkPassphrase: "Test SDF Network ; September 2015",
contractId: "CC5ELPSQFQMJ75XUPJARIODNA7UIH4RS36N37BAV4SVEBEDN4PJYVL5E",
}
};
export const Errors = {};
export class Client extends ContractClient {
options;
constructor(options) {
super(new ContractSpec(["AAAAAgAAAAAAAAAAAAAAB0RhdGFLZXkAAAAAAgAAAAAAAAAAAAAABUluZGV4AAAAAAAAAQAAAAAAAAAHRW50cmllcwAAAAABAAAAEA==",
"AAAAAQAAAAAAAAAAAAAABUVudHJ5AAAAAAAABQAAAAAAAAADYXByAAAAAAsAAAAAAAAADWVxdWl0eV9zaGFyZXMAAAAAAAPsAAAAEwAAAAsAAAAAAAAABmVzY3JvdwAAAAAACwAAAAAAAAAJaXBmc19oYXNoAAAAAAAAEAAAAAAAAAAOdG90YWxfaW52ZXN0ZWQAAAAAAAs=",
"AAAAAAAAAAAAAAAJc2V0X2VudHJ5AAAAAAAAAQAAAAAAAAAFZW50cnkAAAAAAAfQAAAABUVudHJ5AAAAAAAAAA==",
"AAAAAAAAAAAAAAAJZ2V0X2VudHJ5AAAAAAAAAQAAAAAAAAAJaXBmc19oYXNoAAAAAAAAEAAAAAEAAAfQAAAABUVudHJ5AAAA",
"AAAAAAAAAAAAAAAGaW52ZXN0AAAAAAADAAAAAAAAAAR1c2VyAAAAEwAAAAAAAAAJaXBmc19oYXNoAAAAAAAAEAAAAAAAAAAGYW1vdW50AAAAAAALAAAAAA==",
"AAAAAAAAAAAAAAARZGlzdHJpYnV0ZV9wYXlvdXQAAAAAAAABAAAAAAAAAAlpcGZzX2hhc2gAAAAAAAAQAAAAAA==",
"AAAAAAAAAAAAAAASZGlzdHJpYnV0ZV9wYXlvdXRzAAAAAAAAAAAAAA=="]), options);
this.options = options;
}
fromJSON = {
set_entry: (this.txFromJSON),
get_entry: (this.txFromJSON),
invest: (this.txFromJSON),
distribute_payout: (this.txFromJSON),
distribute_payouts: (this.txFromJSON)
};
}
Loading