Skip to content

viewFunction should accept argsJson in addition to argsBase64 #76

@petersalomonsen

Description

@petersalomonsen

Feature Request

Description

The viewFunction convenience function currently only accepts argsBase64 for passing arguments. It would be more developer-friendly to also accept argsJson as an alternative, which would automatically be converted to base64.

Current API

viewFunction(params: {
  accountId: string;
  methodName: string;
  argsBase64?: string;
  // ...
})

Proposed API

viewFunction(params: {
  accountId: string;
  methodName: string;
  argsBase64?: string;
  argsJson?: any;  // New parameter
  // ...
})

Implementation Notes

  • Should accept either argsBase64 or argsJson, but not both
  • When argsJson is provided, it should be JSON.stringify'd and then base64 encoded
  • Could potentially add a helper function like viewFunctionAsJson that already exists but for input args

Benefits

  • More intuitive API for JavaScript/TypeScript developers
  • Reduces boilerplate of manually encoding JSON to base64
  • Consistent with how other NEAR SDKs handle function arguments

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions