Getting Started with Neo Service Layer
Overview
What You'll Need
- A Neo N3 wallet (NeoLine, O3, Neon, or OneGate)
- Basic knowledge of Neo N3 blockchain and smart contracts
- A text editor or IDE for development
- Node.js installed (for JavaScript/TypeScript development)
Creating an Account
Sign up: Visit the Sign Up page to create an account.
Connect your wallet: Use one of the supported Neo N3 wallets to connect to the service. Your wallet address will be linked to your account.
Connecting your Neo N3 wallet to the Service Layer
Create a project: From your dashboard, create a new project by clicking the "Create Project" button and providing a name and description.
Generate API keys: In your project settings, generate API keys that you'll use to authenticate with the Service Layer.
Authentication
To interact with the Neo Service Layer API, you need to authenticate using your API key:
1// JavaScript example
2const headers = {
3 'Content-Type': 'application/json',
4 'X-API-Key': 'your-api-key-here'
5};
6
7// Example API request
8fetch('https://api.neo-service-layer.io/v1/functions', {
9 method: 'GET',
10 headers: headers
11})
12.then(response => response.json())
13.then(data => console.log(data))
14.catch(error => console.error('Error:', error));
Alternatively, use our SDK which handles authentication for you:
1// Install the SDK
2npm install neo-service-layer-sdk
3
4// JavaScript example
5const { NeoServiceLayer } = require('neo-service-layer-sdk');
6
7// Initialize with your API key
8const serviceLayer = new NeoServiceLayer({
9 apiKey: 'your-api-key-here'
10});
11
12// Now you can access services
13const functionsService = serviceLayer.functions;
14const secretsService = serviceLayer.secrets;
15// etc.
Quick Start Examples
Example 1: Create and Deploy a Function
1// JavaScript example using the SDK
2const { NeoServiceLayer } = require('neo-service-layer-sdk');
3
4const serviceLayer = new NeoServiceLayer({
5 apiKey: 'your-api-key-here'
6});
7
8async function deployFunction() {
9 // Create a simple function
10 const functionCode = `
11 module.exports = async function(context) {
12 const { params } = context;
13 return {
14 message: `Hello, ${params.name || 'World'}!`,
15 timestamp: new Date().toISOString()
16 };
17 };
18 `;
19
20 // Deploy the function
21 const result = await serviceLayer.functions.create({
22 name: 'hello-world',
23 code: functionCode,
24 runtime: 'node16',
25 description: 'A simple hello world function'
26 });
27
28 console.log('Function deployed:', result);
29
30 // Invoke the function
31 const response = await serviceLayer.functions.invoke('hello-world', {
32 name: 'Neo'
33 });
34
35 console.log('Function response:', response);
36}
37
38deployFunction().catch(console.error);
Example 2: Store and Retrieve a Secret
1// JavaScript example using the SDK
2const { NeoServiceLayer } = require('neo-service-layer-sdk');
3
4const serviceLayer = new NeoServiceLayer({
5 apiKey: 'your-api-key-here'
6});
7
8async function manageSecrets() {
9 // Store an API key as a secret
10 await serviceLayer.secrets.set({
11 name: 'external-api-key',
12 value: 'my-api-key-value',
13 description: 'API key for external service'
14 });
15
16 console.log('Secret stored successfully');
17
18 // Use the secret in a function
19 const functionCode = `
20 module.exports = async function(context) {
21 // Access the secret
22 const apiKey = context.secrets['external-api-key'];
23
24 // Use the API key (in a real scenario, you'd make an API call)
25 return {
26 message: 'Successfully used the API key',
27 keyFirstChars: apiKey.substring(0, 3) + '...'
28 };
29 };
30 `;
31
32 // Deploy the function that uses the secret
33 const result = await serviceLayer.functions.create({
34 name: 'use-secret-function',
35 code: functionCode,
36 runtime: 'node16',
37 description: 'Function that uses a secret',
38 secrets: ['external-api-key'] // Request access to this secret
39 });
40
41 // Invoke the function
42 const response = await serviceLayer.functions.invoke('use-secret-function');
43
44 console.log('Function response:', response);
45}
46
47manageSecrets().catch(console.error);
Example 3: Set Up Contract Automation
1// JavaScript example using the SDK
2const { NeoServiceLayer } = require('neo-service-layer-sdk');
3
4const serviceLayer = new NeoServiceLayer({
5 apiKey: 'your-api-key-here'
6});
7
8async function createAutomation() {
9 // Create automation that triggers daily at midnight
10 const automation = await serviceLayer.automation.create({
11 name: 'daily-contract-update',
12 description: 'Updates a contract value every day at midnight',
13
14 // Trigger configuration (time-based)
15 trigger: {
16 type: 'schedule',
17 schedule: '0 0 * * *' // Cron syntax for midnight every day
18 },
19
20 // Action configuration (invoke a contract)
21 action: {
22 type: 'contract',
23 network: 'MainNet',
24 scriptHash: '0x7a16a1f5c40e69790333f3bfe7e4325a08cc2f79',
25 operation: 'updateDailyValue',
26 args: [
27 { type: 'Integer', value: new Date().getTime() }
28 ]
29 }
30 });
31
32 console.log('Automation created:', automation);
33}
34
35createAutomation().catch(console.error);
Next Steps
Functions Service
Learn how to create, deploy, and invoke secure JavaScript functions in our TEE environment.
Secrets Management
Store and manage sensitive data securely in our Trusted Execution Environment.
Contract Automation
Set up automated contract interactions triggered by time or events.
Gas Bank
Learn how to use the Gas Bank service for optimizing transaction costs.