-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
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/deployPOST /api/v1/contract/executePOST /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
- Consistency: Uses same path structure as node implementation
- REST Best Practices: Contract ID in URL path, not request body
- Semantic Clarity:
/blockchain/contracts/*clearly shows resource hierarchy - 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