Overview
Neo Service Layer provides official SDKs for multiple programming languages, enabling seamless integration with your applications.
.NET SDK
Full-featured SDK for .NET applications
dotnet add package NeoServiceLayer.SDK
JavaScript SDK
TypeScript-ready SDK for Node.js and browsers
npm install @neo-service-layer/sdk
Python SDK
Pythonic interface to Neo Service Layer
pip install neo-service-layer
Java SDK
Java SDK with Spring Boot integration
implementation 'com.neo:service-layer:2.0.0'
.NET SDK
Installation
# Using .NET CLI
dotnet add package NeoServiceLayer.SDK
# Using Package Manager
Install-Package NeoServiceLayer.SDK
# Using PackageReference
<PackageReference Include="NeoServiceLayer.SDK" Version="2.0.0" />
Quick Start
using NeoServiceLayer.SDK;
using NeoServiceLayer.SDK.Services;
// Initialize the client
var config = new NeoServiceLayerConfig
{
ApiKey = "your-api-key",
Environment = Environment.Production,
Region = Region.USEast
};
var client = new NeoServiceLayerClient(config);
// Use Enclave Storage Service
var enclaveStorage = client.GetService<IEnclaveStorageService>();
var result = await enclaveStorage.SecureStoreAsync(
key: "sensitive-data",
data: encryptedData,
attestation: attestationReport
);
// Use Smart Contracts Service
var smartContracts = client.GetService<ISmartContractsService>();
var contract = await smartContracts.DeployContractAsync(
contractCode: compiledContract,
parameters: deploymentParams
);
// Use Authentication Service
var auth = client.GetService<IAuthenticationService>();
var token = await auth.AuthenticateAsync(
username: "user@example.com",
password: "secure-password",
mfaCode: "123456"
);
Advanced Features
// Transaction Management
using (var transaction = await client.BeginTransactionAsync())
{
try
{
// Perform multiple operations
await enclaveStorage.StoreAsync(key1, data1);
await smartContracts.ExecuteAsync(contractId, method, args);
await blockchain.SubmitTransactionAsync(tx);
// Commit all operations atomically
await transaction.CommitAsync();
}
catch
{
// Automatic rollback on exception
await transaction.RollbackAsync();
throw;
}
}
// Event Subscriptions
client.Events.OnServiceHealthChanged += (sender, args) =>
{
Console.WriteLine($"Service {args.ServiceName} health: {args.Status}");
};
// Batch Operations
var batchResults = await client.BatchAsync(batch =>
{
batch.Add(enclaveStorage.GetAsync("key1"));
batch.Add(enclaveStorage.GetAsync("key2"));
batch.Add(smartContracts.GetContractAsync(contractId));
});
JavaScript SDK
Installation
# Using npm
npm install @neo-service-layer/sdk
# Using yarn
yarn add @neo-service-layer/sdk
# Using pnpm
pnpm add @neo-service-layer/sdk
Quick Start
import { NeoServiceLayer } from '@neo-service-layer/sdk';
// Initialize the client
const client = new NeoServiceLayer({
apiKey: 'your-api-key',
environment: 'production',
region: 'us-east-1'
});
// Use Enclave Storage Service
const enclaveStorage = client.services.enclaveStorage;
const result = await enclaveStorage.secureStore({
key: 'sensitive-data',
data: encryptedData,
attestation: attestationReport
});
// Use Smart Contracts Service
const smartContracts = client.services.smartContracts;
const contract = await smartContracts.deploy({
code: compiledContract,
parameters: deploymentParams
});
// Use Authentication Service
const auth = client.services.authentication;
const { token } = await auth.authenticate({
username: 'user@example.com',
password: 'secure-password',
mfaCode: '123456'
});
TypeScript Support
import {
NeoServiceLayer,
EnclaveStorageService,
SmartContractDeployment,
AuthenticationResult
} from '@neo-service-layer/sdk';
const client = new NeoServiceLayer({
apiKey: process.env.NEO_API_KEY!,
environment: 'production'
});
// Type-safe service usage
const enclaveStorage: EnclaveStorageService = client.services.enclaveStorage;
// Type-safe responses
const deployment: SmartContractDeployment = await client.services.smartContracts.deploy({
code: contractCode,
parameters: {
name: 'MyContract',
version: '1.0.0'
}
});
// Async/await error handling
try {
const result: AuthenticationResult = await client.services.authentication.authenticate({
username: 'user@example.com',
password: 'password'
});
} catch (error) {
if (error.code === 'AUTH_FAILED') {
console.error('Authentication failed:', error.message);
}
}
Python SDK
Installation
# Using pip
pip install neo-service-layer
# Using poetry
poetry add neo-service-layer
# Using pipenv
pipenv install neo-service-layer
Quick Start
from neo_service_layer import NeoServiceLayer
from neo_service_layer.services import EnclaveStorage, SmartContracts
# Initialize the client
client = NeoServiceLayer(
api_key='your-api-key',
environment='production',
region='us-east-1'
)
# Use Enclave Storage Service
enclave_storage = client.services.enclave_storage
result = await enclave_storage.secure_store(
key='sensitive-data',
data=encrypted_data,
attestation=attestation_report
)
# Use Smart Contracts Service
smart_contracts = client.services.smart_contracts
contract = await smart_contracts.deploy(
code=compiled_contract,
parameters=deployment_params
)
# Use Authentication Service
auth = client.services.authentication
token = await auth.authenticate(
username='user@example.com',
password='secure-password',
mfa_code='123456'
)
Async Context Manager
import asyncio
from neo_service_layer import NeoServiceLayer
async def main():
async with NeoServiceLayer(api_key='your-api-key') as client:
# Automatic connection management
result = await client.services.blockchain.get_block('latest')
# Batch operations
async with client.batch() as batch:
batch.add(client.services.enclave_storage.get('key1'))
batch.add(client.services.enclave_storage.get('key2'))
results = await batch.execute()
# Run the async function
asyncio.run(main())
Java SDK
Installation
<!-- Maven -->
<dependency>
<groupId>com.neo</groupId>
<artifactId>service-layer-sdk</artifactId>
<version>2.0.0</version>
</dependency>
<!-- Gradle -->
implementation 'com.neo:service-layer-sdk:2.0.0'
Quick Start
import com.neo.servicelayer.*;
import com.neo.servicelayer.services.*;
// Initialize the client
NeoServiceLayerConfig config = NeoServiceLayerConfig.builder()
.apiKey("your-api-key")
.environment(Environment.PRODUCTION)
.region(Region.US_EAST)
.build();
NeoServiceLayerClient client = new NeoServiceLayerClient(config);
// Use Enclave Storage Service
EnclaveStorageService enclaveStorage = client.getService(EnclaveStorageService.class);
StoreResult result = enclaveStorage.secureStore(
"sensitive-data",
encryptedData,
attestationReport
).get();
// Use Smart Contracts Service
SmartContractsService smartContracts = client.getService(SmartContractsService.class);
Contract contract = smartContracts.deploy(
compiledContract,
deploymentParams
).get();
// Use Authentication Service
AuthenticationService auth = client.getService(AuthenticationService.class);
AuthToken token = auth.authenticate(
"user@example.com",
"secure-password",
"123456"
).get();
Spring Boot Integration
@Configuration
@EnableNeoServiceLayer
public class NeoServiceLayerConfig {
@Bean
public NeoServiceLayerClient neoServiceLayerClient(
@Value("${neo.api-key}") String apiKey) {
return NeoServiceLayerClient.builder()
.apiKey(apiKey)
.environment(Environment.PRODUCTION)
.build();
}
}
@Service
public class BlockchainService {
@Autowired
private NeoServiceLayerClient client;
public CompletableFuture<TransactionResult> submitTransaction(Transaction tx) {
return client.getService(BlockchainService.class)
.submitTransaction(tx);
}
}
Authentication
All SDKs support multiple authentication methods for secure access to Neo Service Layer services.
API Key Authentication
const client = new NeoServiceLayer({
apiKey: 'your-api-key'
});
OAuth 2.0
const client = new NeoServiceLayer({
oauth: {
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
scope: 'read write'
}
});
JWT Bearer Token
const client = new NeoServiceLayer({
bearerToken: 'your-jwt-token'
});
Mutual TLS
const client = new NeoServiceLayer({
mtls: {
cert: fs.readFileSync('client-cert.pem'),
key: fs.readFileSync('client-key.pem'),
ca: fs.readFileSync('ca-cert.pem')
}
});
Error Handling
All SDKs provide consistent error handling with detailed error codes and messages.
Error Types
Error Code | Description | HTTP Status |
---|---|---|
AUTH_FAILED | Authentication failed | 401 |
PERMISSION_DENIED | Insufficient permissions | 403 |
RESOURCE_NOT_FOUND | Resource not found | 404 |
RATE_LIMIT_EXCEEDED | Rate limit exceeded | 429 |
SERVICE_UNAVAILABLE | Service temporarily unavailable | 503 |
Error Handling Example
try {
const result = await client.services.blockchain.submitTransaction(tx);
} catch (error) {
switch (error.code) {
case 'AUTH_FAILED':
// Refresh authentication
await client.refreshAuth();
break;
case 'RATE_LIMIT_EXCEEDED':
// Wait and retry
await sleep(error.retryAfter);
break;
case 'SERVICE_UNAVAILABLE':
// Use fallback service
await useFallback();
break;
default:
console.error('Unexpected error:', error);
}
}