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

Format code (will add pre-commit format) #52

Merged
merged 1 commit into from
Sep 30, 2023
Merged
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
2 changes: 1 addition & 1 deletion .changeset/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# How to upgrade the version

- Run `yarn changeset` and provide a description of your change.
- Run `yarn changeset` and provide a description of your change.
- Commit the `.md` file generated by `changeset` along with your code changes, then create the PR.
- After your PR merged, Github Workflow will create a PR called "Version Packages" to update the version in `package.json` and the `CHANGELOG.md`.
- Once the "Version Packages" PR is merged, Github Workflow will publish a new version to NPM.
Expand Down
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
- package-ecosystem: 'npm' # See documentation for possible values
directory: '/' # Location of package manifests
schedule:
interval: "weekly"
interval: 'weekly'
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Publish
on:
workflow_run:
workflows: ["CI"]
workflows: ['CI']
types:
- completed
push:
branches:
- "main"
- 'main'

concurrency: ${{ github.workflow }}-${{ github.ref }}

Expand Down
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,22 @@ There are two ways to call a view function with the client:
```typescript
// Option 1. Use the `useABI` interface
const [balance] = await client.useABI(COIN_ABI).view.balance({
arguments: ['0x1'],
type_arguments: ['0x1::aptos_coin::AptosCoin'],
arguments: ['0x1'],
type_arguments: ['0x1::aptos_coin::AptosCoin'],
ledger_version: '562606728', // ledger_version is optional
});

// Option 2. Create payload and use the `view` interface
import { createViewPayload } from "@thalalabs/surf";
import { createViewPayload } from '@thalalabs/surf';
const viewPayload = createViewPayload(COIN_ABI, {
function: 'balance',
arguments: ['0x1'],
type_arguments: ['0x1::aptos_coin::AptosCoin'],
function: 'balance',
arguments: ['0x1'],
type_arguments: ['0x1::aptos_coin::AptosCoin'],
});
const [balance] = await client.view(viewPayload);
const [balance] = await client.view(
viewPayload,
{ ledger_version: '562606728' }, // ledger_version is optional
);
```

Both of the interfaces can provide type safety.
Expand Down Expand Up @@ -132,7 +136,7 @@ const entryPayload = createEntryPayload(COIN_ABI, {
});

const { hash } = await client.submitTransaction(
entryPayload,
entryPayload,
{ account },
);
```
Expand Down Expand Up @@ -160,7 +164,7 @@ const entryPayload = createEntryPayload(COIN_ABI, {
});

const { hash } = await client.simulateTransaction(
entryPayload,
entryPayload,
{ account }
);
```
Expand All @@ -171,8 +175,9 @@ To get account resource with type safety:

```typescript
const { data } = await client.useABI(COIN_ABI).resource.CoinStore({
type_arguments: ['0x1::aptos_coin::AptosCoin'],
account: '0x1',
type_arguments: ['0x1::aptos_coin::AptosCoin'],
account: '0x1',
ledger_version: '562606728', // ledger_version is optional
});

// Get property in the struct with type safety
Expand All @@ -184,6 +189,7 @@ console.log(data.coin.value);
```

Some fields of a stuct may reference external modules.To inference the type of a nested struct, it needs the ABI of the external module. Surf currently only built-in some of the ABIs from 0x1, so that it can inference types like `0x1::coin::Coin`. The type of an unidentifiable field would be `object`. Developer can provide additional modules to Surf like this:

```TypeScript
import { DefaultABITable } from "@thalalabs/surf";
type ABITAble = DefaultABITable & {
Expand Down Expand Up @@ -212,6 +218,7 @@ Surf support some special types like `0x1::object::Object`, `0x1::option::Option
Learning more backgrounds and design details from this [blog post](https://thalalabs.medium.com/introducing-surf-type-safe-typescript-interfaces-react-hooks-for-aptos-39527f41bc39).

## TODOs

Compared to [Viem](https://viem.sh/), Surf is still in its infancy. Any contribution is welcome and appreciated. Here are some TODOs:

- [ ] Deploy a dedicated smart contract on the testnet for Surf to run tests that cover all data types. Currently, Surf has some tests running in CI, but they do not cover all types.
Expand Down
2 changes: 1 addition & 1 deletion example/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Getting Started

Build the root project first. Then run: `node ../build/src/cli.js --config=./move-ts.config.js` in this folder to generate bindings for contract.
Build the root project first. Then run: `node ../build/src/cli.js --config=./move-ts.config.js` in this folder to generate bindings for contract.

Then, run the development server:

Expand Down
Loading
Loading