0xbe1
0xbe1

Reputation: 37

how to pass an Option to arguments when submitting an aptos transaction from TypeScript

In TypeScript, an aptos transaction payload is like this:

const payload = {
  type: "entry_function_payload",
  function: `xxx`,
  type_arguments: [],
  arguments: [str1, str2],
};

In order to call the below entry function from TypeScript:

public entry fun myfun(account: &signer, a: u64, b: u64, c: Option<address>)

I try to pass in a std::option::Option argument. While serializing u64 is as simple as num_a.toString() and num_b.toString(), I haven't figured out how to pass in an std::option::Option argument to transaction payload.

Any help?

Upvotes: 0

Views: 547

Answers (2)

David Wolinsky
David Wolinsky

Reputation: 81

At this point in time, the only types allowed in an entry function are primitive types (integers, vectors, addresses) and the string type. The team is actively exploring how we might introduce more types.

The reason is that types must also have a means for a user to them. For example, a user can not trivially generate a coin. If there were no checks on what types can be passed into an entry function, a user theoretically could define a coin as part of their entry function and generate new coins just by calling that function.

For now, you can simulate an option by using a Vector. In fact, the current option implementation uses vector under the hood.

Upvotes: 1

Stephen Becker
Stephen Becker

Reputation: 11

It is impossible right now to pass Option type from Typescript.

https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/typescript/sdk/src/transaction_builder/builder_utils.ts#L257 This is a function used for parsing the arguments from Typescript.

Upvotes: 1

Related Questions