6.4.17 • Published 3 months ago

@contextdao/sdk v6.4.17

Weekly downloads
-
License
-
Repository
-
Last release
3 months ago

contextv3-sdk

Create a new project ans install Context SDK

mkdir cooldapp
cd cooldapp
npm init -y
npm install --save-dev typescript ts-node
npm install dotenv @contextdao/sdk --save

And then, create a new file: tsconfig.json at the project root:

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "es6",
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist"
  },
  "lib": ["es2015"]
}

Connect to Testnet and read the document 'Context'

import { Context, Network } from '@contextdao/sdk';

async function main() {
    const context = new Context({ network: Network.TESTNET });
    const data = await context.read('context');
    console.log(data);
}

main().catch((error) => { console.error(error); });  

Register a name

import { Context, ContextWallet, ContextDocument } from '@contextdao/sdk';

async function main() {
    // Connect to context
    const context: Context = new Context({
        rpcProviderUrl: process.env.RPC_PROVIDER_URL
    });
    const wallet: ContextWallet = await context.wallet(process.env.PRIVATE_KEY);
    
    // Register the name, makes the address the new owner and deposit 5 tokens
    const fromRegisterDoc: ContextDocument = await context.init('context', wallet);
    await context.register('name_to_register', '0x123', 5, fromRegisterDoc);
}

Write for the first time

    // Initializes the document (first commit).
    const doc: ContextDocument = await context.init(name, wallet);
    doc.write({name: 'First Document'});
    await doc.commit('First Commit');
    await doc.push(Version.MAJOR);

Update the document

    const doc: ContextDocument = await context.clone(name, wallet);
    doc.update({name: 'First Document - Updated', place: 'nowhere'});
    await doc.commit('First Commit');
    await doc.push(Version.PATCH);

Install a new schema

    const doc: ContextDocument = await context.clone(name, wallet);
    doc.install('core/human');
    doc.update('website', 'https://www.ctx.xyz');
    await doc.commit('Added schema');
    await doc.push(Version.MINOR);

Delete a field

    const doc: ContextDocument = await context.clone(name, wallet);
    doc.delete('place');
    await doc.commit('Delete a field');
    await doc.push(Version.PATCH);

Update and push an element in one array.

    // Initializes the document (first commit).
    const doc: ContextDocument = await context.clone(name, wallet);
    doc.push('team', 'alex');
    await doc.commit('Add the element alex into the array team');
    await doc.push(Version.PATCH);
6.4.17

3 months ago

6.4.16

3 months ago

6.4.9

4 months ago

6.4.10

4 months ago

6.4.12

4 months ago

6.4.11

4 months ago

6.4.14

4 months ago

6.4.13

4 months ago

6.4.15

3 months ago

6.4.8

4 months ago

6.4.5

4 months ago

6.4.7

4 months ago

6.4.6

4 months ago

6.3.2

4 months ago

6.4.3

4 months ago

6.4.2

4 months ago

6.4.4

4 months ago

6.4.1

4 months ago

6.4.0

4 months ago

6.3.4

4 months ago

6.3.3

4 months ago

6.3.1

4 months ago

6.3.0

4 months ago

6.1.0

4 months ago

6.1.1

4 months ago

6.0.0

4 months ago

6.2.1

4 months ago

6.2.0

4 months ago

1.3.2

4 months ago

6.2.2

4 months ago

1.3.1

4 months ago

1.3.0

4 months ago

1.2.0

4 months ago

1.1.2

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago

1.1.1

5 months ago

1.1.0

5 months ago

0.2.0

5 months ago

5.0.0

6 months ago

3.9.0

9 months ago

3.4.0

10 months ago

3.2.1

10 months ago

3.2.0

10 months ago

3.8.0

9 months ago

3.6.0

10 months ago

4.0.1

8 months ago

4.0.0

8 months ago

4.0.3

8 months ago

4.2.0

8 months ago

4.0.2

8 months ago

3.3.0

10 months ago

3.7.1

9 months ago

3.7.0

9 months ago

3.1.5

10 months ago

3.5.0

10 months ago

3.1.4

10 months ago

4.3.1

7 months ago

4.1.0

8 months ago

4.3.0

7 months ago

4.1.2

8 months ago

4.1.1

8 months ago

3.1.3

11 months ago

3.1.2

11 months ago

3.1.1

11 months ago

3.1.0

11 months ago

2.10.1

11 months ago

2.3.0

1 year ago

2.2.1

1 year ago

2.10.2

11 months ago

2.2.0

1 year ago

2.5.0

1 year ago

2.4.1

1 year ago

2.3.2

1 year ago

2.10.0

11 months ago

2.4.0

1 year ago

2.3.1

1 year ago

2.2.2

1 year ago

2.7.0

12 months ago

2.6.0

1 year ago

2.9.0

12 months ago

2.8.0

12 months ago

2.7.1

12 months ago

2.1.0

1 year ago

3.0.2

11 months ago

3.0.1

11 months ago

3.0.0

11 months ago

2.10.3

11 months ago

2.10.4

11 months ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago