0.9.6 • Published 3 months ago

@contextprotocol/sdk v0.9.6

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);
0.9.6

3 months ago

0.8.25

4 months ago

0.8.24

4 months ago

0.9.0

4 months ago

0.9.1

4 months ago

0.8.23

4 months ago

0.8.22

4 months ago

0.8.21

4 months ago

0.8.20

4 months ago

0.8.19

4 months ago

0.8.17

4 months ago

0.8.16

4 months ago

0.8.15

4 months ago

0.8.12

4 months ago

0.8.9

4 months ago

0.8.11

4 months ago

0.8.8

4 months ago

0.8.10

4 months ago

0.8.7

4 months ago

0.8.5

4 months ago

0.8.6

4 months ago

0.8.3

4 months ago

0.8.2

4 months ago

0.8.1

4 months ago

0.8.0

4 months ago