Skip to content

[FRONTEND]: Smart contract endpoints incomplete in ZHTP node #8

@umwelt

Description

@umwelt

Problem

The API client library is using old contract paths /api/v1/contract/* instead of the canonical /api/v1/blockchain/contracts/* paths that the ZHTP node implements.

Current State

The library uses these old paths:

  • POST /api/v1/contract/deploy
  • POST /api/v1/contract/execute
  • POST /api/v1/contract/query/{id}

Required Changes

Update src/core/zhtp-api-methods.ts to use canonical contract paths:

Current Path Should Be
POST /api/v1/contract/deploy POST /api/v1/blockchain/contracts/deploy
POST /api/v1/contract/execute POST /api/v1/blockchain/contracts/{id}/call
POST /api/v1/contract/query/{id} GET /api/v1/blockchain/contracts/{id}/state

Implementation Details

File: src/core/zhtp-api-methods.ts

1. Deploy Contract

Current:

return this.request<ContractDeploymentResult>('/api/v1/contract/deploy', {
  method: 'POST',
  // ...
});

Should be:

return this.request<ContractDeploymentResult>('/api/v1/blockchain/contracts/deploy', {
  method: 'POST',
  // ...
});

2. Execute Contract

Current:

return this.request<ContractExecutionResult>('/api/v1/contract/execute', {
  method: 'POST',
  body: JSON.stringify({ contractId, functionName, args }),
});

Should be:

return this.request<ContractExecutionResult>(`/api/v1/blockchain/contracts/${contractId}/call`, {
  method: 'POST',
  body: JSON.stringify({ functionName, args }),
});

3. Query Contract State

Current:

return this.request<any>(`/api/v1/contract/query/${contractId}`, {
  method: 'POST',
  body: JSON.stringify({ functionName, args }),
});

Should be:

return this.request<any>(`/api/v1/blockchain/contracts/${contractId}/state`, {
  method: 'GET',
});

Benefits

  1. Consistency: Uses same path structure as node implementation
  2. REST Best Practices: Contract ID in URL path, not request body
  3. Semantic Clarity: /blockchain/contracts/* clearly shows resource hierarchy
  4. Future-proof: Aligns with node's canonical API structure

Acceptance Criteria

  • Contract deployment path updated to /api/v1/blockchain/contracts/deploy
  • Contract execution uses /api/v1/blockchain/contracts/{id}/call
  • Contract query uses /api/v1/blockchain/contracts/{id}/state
  • Method signatures updated if needed (contractId in URL vs body)
  • Library builds successfully
  • Tests pass (if any)
  • Version bumped appropriately

Priority

P1 - HIGH - Smart contracts are core functionality

Related

  • Node PR #109: Added backward-compatible contract path aliases
  • Node has canonical paths at /api/v1/blockchain/contracts/*

Note

The node currently has aliases for backward compatibility, but the library should use the canonical paths for long-term maintainability.

Metadata

Metadata

Assignees

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