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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@ All notable changes to the Aptos TypeScript SDK will be captured in this file. T

## Added

- [Transactions] Add async variants of argument conversion functions (`convertArgumentWithABI`, `checkOrConvertArgumentWithABI`, `parseArgAsync`) to support fetching module ABIs for struct/enum argument encoding. Original synchronous functions remain unchanged for backwards compatibility.
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

The CHANGELOG states "Add async variants of argument conversion functions" and mentions "Original synchronous functions remain unchanged for backwards compatibility." However, this is misleading - the code shows that the original checkOrConvertArgument and parseArg functions are SYNCHRONOUS and a NEW async variant parseArgAsync and checkOrConvertArgumentWithABI were added. The synchronous checkOrConvertArgument function remains unchanged, which is correct for backwards compatibility. The CHANGELOG should clarify this more accurately to avoid confusion.

Suggested change
- [Transactions] Add async variants of argument conversion functions (`convertArgumentWithABI`, `checkOrConvertArgumentWithABI`, `parseArgAsync`) to support fetching module ABIs for struct/enum argument encoding. Original synchronous functions remain unchanged for backwards compatibility.
- [Transactions] Add new async argument conversion helpers (`convertArgumentWithABI`, `checkOrConvertArgumentWithABI`, `parseArgAsync`) to support fetching module ABIs for struct/enum argument encoding. Existing synchronous functions (`checkOrConvertArgument`, `parseArg`) remain unchanged for backwards compatibility.

Copilot uses AI. Check for mistakes.

- Add JWK caching for keyless authentication with 5-minute TTL to improve performance
- Add `clearMemoizeCache()` utility function for clearing the memoization cache
- Add Bun runtime detection with `isBun()` utility function
- Add warning at `AptosConfig` construction time when running in Bun without explicitly disabling HTTP/2 (Bun does not fully support HTTP/2, which is enabled by default)
- Add Bun runtime CI tests to verify SDK compatibility with Bun
- Add Deno runtime CI tests to verify SDK compatibility with Deno
- Add web environment CI tests using Vitest + jsdom to verify browser compatibility
- [Transactions] Add support for public copy structs and enums as transaction arguments via `MoveStructArgument`, `MoveEnumArgument`, and `StructEnumArgumentParser` classes
- Automatic type inference from function ABI
- Nested structs/enums support (up to 7 levels deep)
- Generic type parameter substitution (T0, T1, etc.)
- Support for all Move primitive types (bool, u8-u256, i8-i256, address)
- Special framework types (String, Object<T>, Option<T>)
- Option<T> dual format support (vector and enum formats)
- Module ABI caching for performance
- Comprehensive validation and error messages
Comment on lines +20 to +28
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

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

This changelog entry claims "Automatic type inference from function ABI" for struct/enum transaction arguments, but in this PR convertArgumentWithABI/checkOrConvertArgumentWithABI aren’t used by the transaction builder (generateTransactionPayload/generateTransactionPayloadWithABI still call the synchronous convertArgument path). As-is, users must pre-encode MoveStructArgument/MoveEnumArgument and won’t get ABI-driven inference via the builder. Either wire the async conversion into the builder or adjust the changelog to match the actual user-facing behavior.

Copilot uses AI. Check for mistakes.

## Changed

Expand Down
82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,88 @@ async function example() {
example();
```

### Using Struct and Enum Arguments

---

The SDK supports passing public copy structs and enums as transaction arguments. You must encode them using the `StructEnumArgumentParser` before passing to transaction building functions:

```ts
import {
Aptos,
AptosConfig,
Network,
StructEnumArgumentParser,
parseTypeTag,
TypeTagStruct
} from "@aptos-labs/ts-sdk";

const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
const parser = new StructEnumArgumentParser(config);

// Example 1: Simple struct argument
const pointType = parseTypeTag("0x1::shapes::Point") as TypeTagStruct;
const pointArg = await parser.encodeStructArgument(pointType, { x: "10", y: "20" });

const transaction = await aptos.transaction.build.simple({
sender: alice.accountAddress,
data: {
function: "0x1::shapes::draw_point",
functionArguments: [pointArg],
},
});

// Example 2: Nested structs
const lineType = parseTypeTag("0x1::shapes::Line") as TypeTagStruct;
const lineArg = await parser.encodeStructArgument(lineType, {
start: { x: "0", y: "0" },
end: { x: "10", y: "10" }
});

const transaction2 = await aptos.transaction.build.simple({
sender: alice.accountAddress,
data: {
function: "0x1::shapes::draw_line",
functionArguments: [lineArg],
},
});

// Example 3: Enum variants
const colorType = parseTypeTag("0x1::game::Color") as TypeTagStruct;
const colorArg = await parser.encodeEnumArgument(colorType, { Red: {} });

const transaction3 = await aptos.transaction.build.simple({
sender: alice.accountAddress,
data: {
function: "0x1::game::set_color",
functionArguments: [colorArg],
},
});

// Example 4: Enum with fields
const accountTypeTag = parseTypeTag("0x1::game::AccountType") as TypeTagStruct;
const accountTypeArg = await parser.encodeEnumArgument(accountTypeTag, {
Premium: { "0": "100" }
});

const transaction4 = await aptos.transaction.build.simple({
sender: alice.accountAddress,
data: {
function: "0x1::game::create_player",
functionArguments: [accountTypeArg],
},
});
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

The README documentation shows explicit encoding with StructEnumArgumentParser, but the PR description states that the SDK supports "Automatic type inference from function ABI". According to the implementation in remoteAbi.ts, plain objects can be passed directly to functionArguments and will be automatically encoded. The README should include an example showing this automatic inference capability, e.g., functionArguments: [{ x: "10", y: "20" }] without explicit parser.encodeStructArgument() call, to demonstrate the full feature set.

Suggested change
});
});
// Example 5: Automatic type inference from function ABI (no explicit encoding)
// Assuming 0x1::game::set_position takes a struct { x: u64, y: u64 } as its argument.
const positionTypeTag = parseTypeTag("0x1::game::Position") as TypeTagStruct;
const transaction5 = await aptos.transaction.build.simple({
sender: alice.accountAddress,
data: {
function: "0x1::game::set_position",
// Plain object is automatically encoded based on the function ABI
functionArguments: [{ x: "10", y: "20" }],
},
});

Copilot uses AI. Check for mistakes.
```

**Features:**
- Support for nested structs/enums (up to 7 levels deep)
- Generic type parameter substitution (T0, T1, etc.)
- All Move primitive types (bool, u8-u256, i8-i256, address)
- Special framework types (String, Object<T>, Option<T>)
- Option<T> dual format support (vector `[]`/`[value]` or enum `{None:{}}`/`{Some:{0:value}}`)
- Module ABI caching for performance

## Troubleshooting

If you see an import error when you do this:
Expand Down
Loading
Loading