@contextdao/sdk v6.4.17
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);
3 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
6 months ago
9 months ago
10 months ago
10 months ago
10 months ago
9 months ago
10 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
10 months ago
9 months ago
9 months ago
10 months ago
10 months ago
10 months ago
7 months ago
8 months ago
7 months ago
8 months ago
8 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
12 months ago
1 year ago
12 months ago
12 months ago
12 months ago
1 year ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago