Skip to content

Commit 91e7995

Browse files
authored
Merge pull request #25 from dimitrov-d/master
3.0.0 (Phala SDK, Substrate NFTs, Social SDK)
2 parents eb6b379 + 4966970 commit 91e7995

33 files changed

+1148
-155
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apillon-web3-tools",
3-
"version": "2.0.0",
3+
"version": "3.0.0",
44
"description": "Monorepo for Apillon tools",
55
"author": "Apillon",
66
"license": "MIT",

packages/cli/README.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,7 @@ apillon storage list-objects --bucket-uuid "123e4567-e89b-12d3-a456-426655440000
302302
"updateTime": "2023-11-23T08:55:46.000Z",
303303
"uuid": "14a7a891-877c-41ac-900c-7382347e1e77",
304304
"name": "index.html",
305-
"CID": "QmWX5CcNvnaVmgGBn4o82XW9uW1uLvsHQDdNrANrQeSdXm",
306-
"CIDv1": "bafybeidzrd7p5ddj67j2mud32cbnze2c7b2pvbhn...",
305+
"CID": "bafybeidzrd7p5ddj67j2mud32cbnze2c7b2pvbhn...",
307306
"status": "AVAILABLE_ON_IPFS_AND_REPLICATED",
308307
"directoryUuid": null,
309308
"type": "FILE",
@@ -350,8 +349,7 @@ apillon storage list-files --bucket-uuid "123e4567-e89b-12d3-a456-426655440000"
350349
"createTime": "2023-11-15T09:58:04.000Z",
351350
"updateTime": "2023-11-15T09:58:10.000Z",
352351
"name": "style.css",
353-
"CID": "QmWX5CcNvnaVmgGBn4o82XW9uW1uLvsHQDdNrANrQeSdXm",
354-
"CIDv1": "bafybeidzrd7p5ddj67j2mud32cbnze2c7b2pvbag...",
352+
"CID": "bafybeidzrd7p5ddj67j2mud32cbnze2c7b2pvbag...",
355353
"status": "AVAILABLE_ON_IPFS_AND_REPLICATED",
356354
"directoryUuid": null,
357355
"type": "FILE",
@@ -438,7 +436,7 @@ Lists all IPNS records for a specific bucket.
438436

439437
**Example**
440438
```sh
441-
apillon ipns list --bucket-uuid "123e4567-e89b-12d3-a456-426655440000"
439+
apillon storage ipns list --bucket-uuid "123e4567-e89b-12d3-a456-426655440000"
442440
```
443441

444442
**Example response**
@@ -484,41 +482,44 @@ Creates a new IPNS record for a specific bucket.
484482

485483
**Example**
486484
```sh
487-
apillon ipns create --bucket-uuid "123e4567-e89b-12d3-a456-426655440000" --name "my-ipns-record" --cid "QmWX5CcNvnaVmgGBn4o82XW9uW1uLvsHQDdNrANrQeSdXm"
485+
apillon storage ipns create --bucket-uuid "123e4567-e89b-12d3-a456-426655440000" --name "my-ipns-record" --cid "QmWX5CcNvnaVmgGBn4o82XW9uW1uLvsHQDdNrANrQeSdXm"
488486
```
489487

490488
#### `storage ipns get`
491489
Retrieves information about a specific IPNS record.
492490

493491
**Options**
492+
- `-b, --bucket-uuid <uuid>`: UUID of the bucket.
494493
- `-i, --ipns-uuid <uuid>`: UUID of the IPNS record.
495494

496495
**Example**
497496
```sh
498-
apillon ipns get --ipns-uuid "123e4567-e89b-12d3-a456-426655440000"
497+
apillon storage ipns get --ipns-uuid "123e4567-e89b-12d3-a456-426655440000"
499498
```
500499

501500
#### `storage ipns publish`
502501
Publishes an IPNS record to IPFS and links it to a CID.
503502

504503
**Options**
504+
- `-b, --bucket-uuid <uuid>`: UUID of the bucket.
505505
- `-i, --ipns-uuid <uuid>`: UUID of the IPNS record.
506506
- `-c, --cid <string>`: CID to which this IPNS name will point.
507507

508508
**Example**
509509
```sh
510-
apillon ipns publish --ipns-uuid "123e4567-e89b-12d3-a456-426655440000" --cid "QmWX5CcNvnaVmgGBn4o82XW9uW1uLvsHQDdNrANrQeSdXm"
510+
apillon storage ipns publish --ipns-uuid "123e4567-e89b-12d3-a456-426655440000" --cid "QmWX5CcNvnaVmgGBn4o82XW9uW1uLvsHQDdNrANrQeSdXm"
511511
```
512512

513513
#### `storage ipns delete`
514514
Deletes an IPNS record from a specific bucket.
515515

516516
**Options**
517+
- `-b, --bucket-uuid <uuid>`: UUID of the bucket.
517518
- `-i, --ipns-uuid <uuid>`: UUID of the IPNS record.
518519

519520
**Example**
520521
```sh
521-
apillon ipns delete --ipns-uuid "123e4567-e89b-12d3-a456-426655440000"
522+
apillon storage ipns delete --ipns-uuid "123e4567-e89b-12d3-a456-426655440000"
522523
```
523524

524525
## NFT Commands

packages/sdk/README.md

+116-15
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ as well as compresses multi step flows into single operations.
99

1010
## Requirements
1111

12-
- npm 8.4.0 or higher
13-
- node.js 16.17.0 or higher
12+
- npm 10.0.0 or higher
13+
- node.js 20.0.0 or higher
1414
- Apillon API key and secret
1515

1616
## Getting started
@@ -46,6 +46,12 @@ View each individual module examples in the sections below.
4646

4747
This wiki only contains the basic installation and examples of SDK usage. For additional information on using the SDK, see the [Detailed SDK documentation](https://sdk-docs.apillon.io/).
4848

49+
### Examples
50+
51+
Examples for using Apillon can be found in a demo repo [here](https://github.com/Apillon/apillon-sdk-demo). Instructions on running the examples are in the [README file](https://github.com/Apillon/apillon-sdk-demo/blob/master/README.md).
52+
53+
> You can run examples directly in your browser via [CodeSandbox](https://codesandbox.io/p/github/Apillon/apillon-sdk-demo/master).
54+
4955
## Hosting
5056

5157
Hosting module encapsulates functionalities for Hosting service available on Apillon dashboard.
@@ -76,7 +82,7 @@ import * as fs from 'fs';
7682
const hosting = new Hosting({
7783
key: 'yourApiKey',
7884
secret: 'yourApiSecret',
79-
logLevel: LogLevel.NONE,
85+
logLevel: LogLevel.VERBOSE,
8086
});
8187

8288
// list all websites
@@ -134,7 +140,7 @@ import * as fs from 'fs';
134140
const storage = new Storage({
135141
key: 'yourApiKey',
136142
secret: 'yourApiSecret',
137-
logLevel: LogLevel.NONE,
143+
logLevel: LogLevel.VERBOSE,
138144
});
139145

140146
// list buckets
@@ -190,7 +196,7 @@ import { Storage, LogLevel } from '@apillon/sdk';
190196
const storage = new Storage({
191197
key: 'yourApiKey',
192198
secret: 'yourApiSecret',
193-
logLevel: LogLevel.NONE,
199+
logLevel: LogLevel.VERBOSE,
194200
});
195201

196202
// create and instance of a bucket directly through uuid
@@ -235,11 +241,11 @@ import {
235241
const nft = new Nft({
236242
key: 'yourApiKey',
237243
secret: 'yourApiSecret',
238-
logLevel: LogLevel.NONE,
244+
logLevel: LogLevel.VERBOSE,
239245
});
240246

241247
// create a new collection
242-
const collection1 = await nft.create({
248+
let collection = await nft.create({
243249
collectionType: CollectionType.GENERIC,
244250
chain: EvmChain.MOONBEAM,
245251
name: 'SpaceExplorers',
@@ -258,20 +264,31 @@ const collection1 = await nft.create({
258264
dropPrice: 0.05,
259265
dropReserve: 100,
260266
});
267+
// or create a substrate collection
268+
const substrateCollection = await nft.createSubstrate({
269+
collectionType: CollectionType.GENERIC,
270+
chain: SubstrateChain.ASTAR,
271+
name: 'SpaceExplorers',
272+
symbol: 'SE',
273+
...
274+
});
261275

262276
// check if collection is deployed - available on chain
263-
if (collection1.collectionStatus == CollectionStatus.DEPLOYED) {
264-
console.log('Collection deployed: ', collection1.transactionHash);
277+
if (collection.collectionStatus == CollectionStatus.DEPLOYED) {
278+
console.log('Collection deployed: ', collection.transactionHash);
265279
}
266280

267281
// search through collections
268282
await nft.listCollections({ search: 'My NFT' });
269283

270284
// create and instance of collection directly through uuid
271-
const collection = await nft.collection('uuid').get();
285+
collection = await nft.collection('uuid').get();
272286

273287
// mint a new nft in the collection
274-
await collection.mint('0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD', 1);
288+
await collection.mint({
289+
receivingAddress: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
290+
quantity: 1,
291+
});
275292

276293
// nest mint a new nft if collection type is NESTABLE
277294
await collection.nestMint(collection.uuid, 1, 1);
@@ -292,7 +309,6 @@ await collection.transferOwnership(
292309
);
293310
```
294311

295-
296312
## Identity
297313

298314
Identity module encapsulates functionalities for validating EVM and Polkadot wallet signatures, as well as fetching Polkadot Identity data for any wallet.
@@ -302,14 +318,13 @@ For detailed hosting SDK method, class and property documentation visit [SDK ide
302318
### Usage example
303319

304320
```ts
305-
import { Identity } from './modules/identity/identity';
306-
import { LogLevel } from './types/apillon';
321+
import { Identity, LogLevel } from '@apillon/sdk';
307322

308323
// Note: for signature-related methods API config is not required
309324
const identity = new Identity({
310325
key: 'yourApiKey',
311326
secret: 'yourApiSecret',
312-
logLevel: LogLevel.NONE,
327+
logLevel: LogLevel.VERBOSE,
313328
});
314329

315330
// obtain on-chain identity data for a Polkadot wallet
@@ -364,4 +379,90 @@ async function validatePolkadotWalletSignature() {
364379
}
365380

366381
```
382+
## Computing
383+
384+
The Computing module provides functionalities for managing computing contracts, including creating contracts, listing contracts, and interacting with specific contracts for operations like encryption and ownership transfer.
385+
386+
### Usage example
387+
388+
```ts
389+
import { Computing } from '@apillon/sdk';
390+
391+
const computing = new Computing({
392+
key: 'yourApiKey',
393+
secret: 'yourApiSecret',
394+
});
395+
396+
// List all computing contracts
397+
const contracts = await computing.listContracts();
398+
399+
// Create a new computing contract
400+
const newContract = await computing.createContract({
401+
name: 'New Contract',
402+
description: 'Description of the new contract',
403+
bucket_uuid,
404+
contractData: {
405+
nftContractAddress: '0xabc...',
406+
nftChainRpcUrl: ChainRpcUrl.ASTAR,
407+
},
408+
});
409+
410+
// Interact with a specific computing contract
411+
const contract = computing.contract(newContract.uuid);
412+
413+
// Get details of the contract
414+
const contractDetails = await contract.get();
415+
416+
// List transactions of the contract
417+
const transactions = await contract.listTransactions();
418+
419+
// Encrypt a file and upload it to the associated bucket
420+
const encryptionResult = await contract.encryptFile({
421+
fileName: 'example.txt',
422+
content: Buffer.from('Hello, world!'),
423+
nftId: 1, // NFT ID used for decryption authentication
424+
});
425+
426+
// Transfer ownership of the contract
427+
const newOwnerAddress = '0xNewOwnerAddress';
428+
const successResult = await contract.transferOwnership(newOwnerAddress);
429+
console.log(
430+
`Ownership transfer was ${successResult ? 'successful' : 'unsuccessful'}.`,
431+
);
432+
```
433+
434+
## Social
435+
436+
The Social module provides functionalities for managing social hubs and channels within the Apillon platform. This includes creating, listing, and interacting with hubs and channels. In the background it utilizes Grill.chat, a mobile-friendly, anonymous chat application powered by Subsocial.
437+
438+
### Usage example
439+
440+
```ts
441+
import { Social } from '@apillon/sdk';
442+
443+
const social = new Social({ key: 'yourApiKey', secret: 'yourApiSecret' });
444+
// Create a new hub
445+
const hub = await social.createHub({
446+
name: 'Apillon Hub',
447+
about: 'Hub for Apillon channels',
448+
tags: 'apillon,web3,build',
449+
});
450+
451+
// Get a specific hub by UUID
452+
const hubDetails = await social.hub(hub.uuid).get();
453+
// List all Hubs
454+
const hubs = await social.listHubs();
455+
456+
// Create a new channel within a hub
457+
const channel = await social.createChannel({
458+
title: 'Web3 Channel',
459+
body: "Let's discuss Web3",
460+
tags: 'web3,crypto',
461+
hubUuid: hub.uuid,
462+
});
367463

464+
// Get a specific channel by UUID
465+
const channelDetails = await social.channel(channel.uuid).get();
466+
// List all channels within a Hub
467+
const channels = await social.listChannels({ hubUuid: hub.uuid });
468+
```

packages/sdk/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@apillon/sdk",
33
"description": "▶◀ Apillon SDK for NodeJS ▶◀",
4-
"version": "2.0.1",
4+
"version": "3.0.0",
55
"author": "Apillon",
66
"license": "MIT",
77
"main": "./dist/index.js",

packages/sdk/src/docs-index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from './types/nfts';
33
export * from './types/hosting';
44
export * from './types/storage';
55
export * from './types/identity';
6+
export * from './types/computing';
67
export * from './lib/apillon';
78
export * from './modules/storage/storage';
89
export * from './modules/storage/storage-bucket';
@@ -15,3 +16,8 @@ export * from './modules/hosting/hosting-website';
1516
export * from './modules/nft/nft';
1617
export * from './modules/nft/nft-collection';
1718
export * from './modules/identity/identity';
19+
export * from './modules/computing/computing';
20+
export * from './modules/computing/computing-contract';
21+
export * from './modules/social/social';
22+
export * from './modules/social/social-hub';
23+
export * from './modules/social/social-channel';

packages/sdk/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ export * from './modules/storage/storage';
99
export * from './modules/hosting/hosting';
1010
export * from './modules/nft/nft';
1111
export * from './modules/identity/identity';
12+
export * from './modules/computing/computing';
13+
export * from './modules/social/social';

packages/sdk/src/lib/apillon-api.ts

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export class ApillonApi {
6161
}
6262
},
6363
);
64+
65+
return config;
6466
}
6567

6668
public static async get<T>(url: string, config?: any): Promise<T> {

packages/sdk/src/lib/apillon.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ export interface ApillonConfig {
3131
}
3232

3333
export class ApillonModule {
34+
protected config: ApillonConfig;
35+
3436
public constructor(config?: ApillonConfig) {
35-
ApillonApi.initialize(config);
37+
this.config = ApillonApi.initialize(config);
3638
ApillonLogger.initialize(
3739
config?.debug ? LogLevel.VERBOSE : config?.logLevel || LogLevel.ERROR,
3840
);
@@ -71,8 +73,7 @@ export class ApillonModel {
7173
protected populate(data: object) {
7274
if (data != null) {
7375
Object.keys(data || {}).forEach((key) => {
74-
const prop = this[key];
75-
if (prop === null) {
76+
if (this[key] === null) {
7677
this[key] = data[key];
7778
}
7879
});

0 commit comments

Comments
 (0)