@kynesyslabs/demosdk 2.3.27 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Contract deployment functionality for Demos SDK
3
+ */
4
+ import { Demos } from '../websdk/demosclass';
5
+ import { ContractDeploymentResult, ContractDeployOptions } from './types/ContractABI';
6
+ import { ContractInstance } from './ContractInstance';
7
+ export declare class ContractDeployer {
8
+ private demos;
9
+ constructor(demos: Demos);
10
+ /**
11
+ * Deploy a new smart contract
12
+ * @param source TypeScript source code of the contract
13
+ * @param constructorArgs Arguments for the contract constructor
14
+ * @param options Deployment options
15
+ * @returns Deployment result with contract address
16
+ */
17
+ deploy(source: string, constructorArgs?: any[], options?: ContractDeployOptions): Promise<ContractDeploymentResult>;
18
+ /**
19
+ * Deploy a contract and return an instance wrapper
20
+ */
21
+ deployAndWrap<T = any>(source: string, constructorArgs?: any[], options?: ContractDeployOptions): Promise<ContractInstance<T>>;
22
+ /**
23
+ * Validate contract source code
24
+ */
25
+ private validateSourceCode;
26
+ /**
27
+ * Build deployment transaction
28
+ */
29
+ private buildDeployTransaction;
30
+ /**
31
+ * Wait for contract deployment confirmation
32
+ */
33
+ private waitForDeployment;
34
+ }
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ /**
3
+ * Contract deployment functionality for Demos SDK
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.ContractDeployer = void 0;
40
+ const ContractInstance_1 = require("./ContractInstance");
41
+ const unifiedCrypto_1 = require("../encryption/unifiedCrypto");
42
+ const skeletons = __importStar(require("../websdk/utils/skeletons"));
43
+ class ContractDeployer {
44
+ constructor(demos) {
45
+ this.demos = demos;
46
+ }
47
+ /**
48
+ * Deploy a new smart contract
49
+ * @param source TypeScript source code of the contract
50
+ * @param constructorArgs Arguments for the contract constructor
51
+ * @param options Deployment options
52
+ * @returns Deployment result with contract address
53
+ */
54
+ async deploy(source, constructorArgs = [], options = {}) {
55
+ try {
56
+ // Validate wallet connection
57
+ if (!this.demos.walletConnected) {
58
+ throw new Error('Wallet not connected. Please connect a wallet first.');
59
+ }
60
+ // Validate source code
61
+ if (options.validateSource !== false) {
62
+ this.validateSourceCode(source);
63
+ }
64
+ // Prepare deployment payload
65
+ const deployPayload = {
66
+ source,
67
+ constructorArgs,
68
+ metadata: options.metadata
69
+ };
70
+ // Build the deployment transaction
71
+ const tx = await this.buildDeployTransaction(deployPayload, options);
72
+ // Send the transaction
73
+ const rpcResult = await this.demos.rpcCall({
74
+ method: 'sendTransaction',
75
+ params: [tx]
76
+ });
77
+ if (rpcResult.result !== 200) {
78
+ return {
79
+ success: false,
80
+ error: rpcResult.response?.error || 'Deployment failed'
81
+ };
82
+ }
83
+ // Wait for confirmation if requested
84
+ if (options.waitForConfirmation !== false) {
85
+ const confirmation = await this.waitForDeployment(rpcResult.response.transactionHash, options.confirmations || 1);
86
+ if (!confirmation.success) {
87
+ return {
88
+ success: false,
89
+ error: confirmation.error
90
+ };
91
+ }
92
+ return {
93
+ success: true,
94
+ contractAddress: confirmation.contractAddress,
95
+ deploymentTx: rpcResult.response.transactionHash,
96
+ gasUsed: confirmation.gasUsed,
97
+ blockHeight: confirmation.blockHeight
98
+ };
99
+ }
100
+ return {
101
+ success: true,
102
+ deploymentTx: rpcResult.response.transactionHash,
103
+ contractAddress: rpcResult.response.contractAddress
104
+ };
105
+ }
106
+ catch (error) {
107
+ return {
108
+ success: false,
109
+ error: error.message || 'Contract deployment failed'
110
+ };
111
+ }
112
+ }
113
+ /**
114
+ * Deploy a contract and return an instance wrapper
115
+ */
116
+ async deployAndWrap(source, constructorArgs = [], options = {}) {
117
+ const result = await this.deploy(source, constructorArgs, options);
118
+ if (!result.success || !result.contractAddress) {
119
+ throw new Error(result.error || 'Deployment failed');
120
+ }
121
+ return new ContractInstance_1.ContractInstance(this.demos, result.contractAddress, options.metadata?.abi);
122
+ }
123
+ /**
124
+ * Validate contract source code
125
+ */
126
+ validateSourceCode(source) {
127
+ // Check for basic contract structure
128
+ if (!source.includes('DemosContract')) {
129
+ throw new Error('Contract must extend DemosContract');
130
+ }
131
+ // Check for banned APIs
132
+ const bannedAPIs = [
133
+ 'eval', 'Function', 'setTimeout', 'setInterval',
134
+ 'XMLHttpRequest', 'fetch', 'WebSocket', 'Worker'
135
+ ];
136
+ for (const api of bannedAPIs) {
137
+ if (source.includes(api)) {
138
+ throw new Error(`Banned API detected: ${api}`);
139
+ }
140
+ }
141
+ // Check size limit (256KB)
142
+ const sizeInBytes = new TextEncoder().encode(source).length;
143
+ if (sizeInBytes > 256 * 1024) {
144
+ throw new Error(`Contract too large: ${sizeInBytes} bytes (max 256KB)`);
145
+ }
146
+ }
147
+ /**
148
+ * Build deployment transaction
149
+ */
150
+ async buildDeployTransaction(payload, options) {
151
+ const { publicKey } = await this.demos.crypto.getIdentity('ed25519');
152
+ const publicKeyHex = (0, unifiedCrypto_1.uint8ArrayToHex)(publicKey);
153
+ const nonce = await this.demos.getAddressNonce(publicKeyHex);
154
+ const tx = structuredClone(skeletons.transaction);
155
+ tx.content.type = 'contractDeploy';
156
+ tx.content.data = ['contractDeploy', payload];
157
+ tx.content.nonce = options.nonce || nonce;
158
+ tx.content.from = publicKeyHex;
159
+ tx.content.timestamp = Date.now();
160
+ tx.content.amount = Number(options.value || 0);
161
+ // Sign the transaction
162
+ return await this.demos.sign(tx);
163
+ }
164
+ /**
165
+ * Wait for contract deployment confirmation
166
+ */
167
+ async waitForDeployment(txHash, confirmations) {
168
+ const maxAttempts = 30; // 30 seconds timeout
169
+ let attempts = 0;
170
+ while (attempts < maxAttempts) {
171
+ const result = await this.demos.rpcCall({
172
+ method: 'getTransactionReceipt',
173
+ params: [txHash]
174
+ });
175
+ if (result.result === 200 && result.response) {
176
+ const receipt = result.response;
177
+ if (receipt.confirmations >= confirmations) {
178
+ return {
179
+ success: true,
180
+ contractAddress: receipt.contractAddress,
181
+ gasUsed: receipt.gasUsed,
182
+ blockHeight: receipt.blockHeight
183
+ };
184
+ }
185
+ }
186
+ await new Promise(resolve => setTimeout(resolve, 1000));
187
+ attempts++;
188
+ }
189
+ return {
190
+ success: false,
191
+ error: 'Deployment confirmation timeout'
192
+ };
193
+ }
194
+ }
195
+ exports.ContractDeployer = ContractDeployer;
196
+ //# sourceMappingURL=ContractDeployer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContractDeployer.js","sourceRoot":"","sources":["../../../src/contracts/ContractDeployer.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASH,yDAAqD;AAGrD,+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IAAI,CAAC,CAAC,CAAA;YACvD,QAAQ,EAAE,CAAA;QACd,CAAC;QAED,OAAO;YACH,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,iCAAiC;SAC3C,CAAA;IACL,CAAC;CACJ;AAnMD,4CAmMC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Factory for creating contract instances
3
+ */
4
+ import { Demos } from '../websdk/demosclass';
5
+ import { ContractDeployer } from './ContractDeployer';
6
+ import { ContractInteractor } from './ContractInteractor';
7
+ import { ContractInstance } from './ContractInstance';
8
+ import { ContractABI, ContractDeployOptions } from './types/ContractABI';
9
+ export declare class ContractFactory {
10
+ private demos;
11
+ private deployer;
12
+ private interactor;
13
+ constructor(demos: Demos);
14
+ /**
15
+ * Deploy a new contract
16
+ */
17
+ deploy(source: string, constructorArgs?: any[], options?: ContractDeployOptions): Promise<ContractInstance>;
18
+ /**
19
+ * Get an instance of an existing contract
20
+ */
21
+ at<T = any>(address: string, abi?: ContractABI): Promise<ContractInstance<T>>;
22
+ /**
23
+ * Create a batch operation builder
24
+ */
25
+ batch(): BatchBuilder;
26
+ /**
27
+ * Estimate gas for a contract call
28
+ */
29
+ estimateGas(contractAddress: string, method: string, args?: any[]): Promise<bigint>;
30
+ }
31
+ /**
32
+ * Batch operation builder
33
+ */
34
+ export declare class BatchBuilder {
35
+ private demos;
36
+ private deployer;
37
+ private interactor;
38
+ private operations;
39
+ constructor(demos: Demos, deployer: ContractDeployer, interactor: ContractInteractor);
40
+ /**
41
+ * Add a deployment to the batch
42
+ */
43
+ deploy(source: string, constructorArgs?: any[], options?: ContractDeployOptions): BatchBuilder;
44
+ /**
45
+ * Add a contract call to the batch
46
+ */
47
+ call(contractAddress: string, method: string, args?: any[]): BatchBuilder;
48
+ /**
49
+ * Execute all operations in the batch
50
+ */
51
+ execute(): Promise<any[]>;
52
+ }
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ /**
3
+ * Factory for creating contract instances
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BatchBuilder = exports.ContractFactory = void 0;
7
+ const ContractDeployer_1 = require("./ContractDeployer");
8
+ const ContractInteractor_1 = require("./ContractInteractor");
9
+ const ContractInstance_1 = require("./ContractInstance");
10
+ class ContractFactory {
11
+ constructor(demos) {
12
+ this.demos = demos;
13
+ this.deployer = new ContractDeployer_1.ContractDeployer(demos);
14
+ this.interactor = new ContractInteractor_1.ContractInteractor(demos);
15
+ }
16
+ /**
17
+ * Deploy a new contract
18
+ */
19
+ async deploy(source, constructorArgs = [], options = {}) {
20
+ return await this.deployer.deployAndWrap(source, constructorArgs, options);
21
+ }
22
+ /**
23
+ * Get an instance of an existing contract
24
+ */
25
+ async at(address, abi) {
26
+ return new ContractInstance_1.ContractInstance(this.demos, address, abi);
27
+ }
28
+ /**
29
+ * Create a batch operation builder
30
+ */
31
+ batch() {
32
+ return new BatchBuilder(this.demos, this.deployer, this.interactor);
33
+ }
34
+ /**
35
+ * Estimate gas for a contract call
36
+ */
37
+ async estimateGas(contractAddress, method, args = []) {
38
+ const result = await this.demos.rpcCall({
39
+ method: 'estimateGas',
40
+ params: [{
41
+ contractAddress,
42
+ method,
43
+ args
44
+ }]
45
+ });
46
+ if (result.result === 200) {
47
+ return BigInt(result.response.gasEstimate || 0);
48
+ }
49
+ throw new Error('Failed to estimate gas');
50
+ }
51
+ }
52
+ exports.ContractFactory = ContractFactory;
53
+ /**
54
+ * Batch operation builder
55
+ */
56
+ class BatchBuilder {
57
+ constructor(demos, deployer, interactor) {
58
+ this.demos = demos;
59
+ this.deployer = deployer;
60
+ this.interactor = interactor;
61
+ this.operations = [];
62
+ }
63
+ /**
64
+ * Add a deployment to the batch
65
+ */
66
+ deploy(source, constructorArgs = [], options = {}) {
67
+ this.operations.push(async () => await this.deployer.deploy(source, constructorArgs, options));
68
+ return this;
69
+ }
70
+ /**
71
+ * Add a contract call to the batch
72
+ */
73
+ call(contractAddress, method, args = []) {
74
+ this.operations.push(async () => await this.interactor.call(contractAddress, method, args));
75
+ return this;
76
+ }
77
+ /**
78
+ * Execute all operations in the batch
79
+ */
80
+ async execute() {
81
+ const results = [];
82
+ for (const operation of this.operations) {
83
+ try {
84
+ const result = await operation();
85
+ results.push(result);
86
+ }
87
+ catch (error) {
88
+ results.push({
89
+ success: false,
90
+ error: error.message
91
+ });
92
+ }
93
+ }
94
+ return results;
95
+ }
96
+ }
97
+ exports.BatchBuilder = BatchBuilder;
98
+ //# sourceMappingURL=ContractFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContractFactory.js","sourceRoot":"","sources":["../../../src/contracts/ContractFactory.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAGH,yDAAqD;AACrD,6DAAyD;AACzD,yDAAqD;AAGrD,MAAa,eAAe;IAIxB,YAAoB,KAAY;QAAZ,UAAK,GAAL,KAAK,CAAO;QAC5B,IAAI,CAAC,QAAQ,GAAG,IAAI,mCAAgB,CAAC,KAAK,CAAC,CAAA;QAC3C,IAAI,CAAC,UAAU,GAAG,IAAI,uCAAkB,CAAC,KAAK,CAAC,CAAA;IACnD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CACR,MAAc,EACd,kBAAyB,EAAE,EAC3B,UAAiC,EAAE;QAEnC,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,CAAC,CAAA;IAC9E,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,EAAE,CACJ,OAAe,EACf,GAAiB;QAEjB,OAAO,IAAI,mCAAgB,CAAI,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,CAAA;IAC5D,CAAC;IAED;;OAEG;IACH,KAAK;QACD,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;IACvE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CACb,eAAuB,EAC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,GAAG,EAAE,CAAA;QAClB,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACtC,IAAI,CAAC;gBACD,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAA;gBAChC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YACxB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,OAAO,CAAC,IAAI,CAAC;oBACT,OAAO,EAAE,KAAK;oBACd,KAAK,EAAG,KAAe,CAAC,OAAO;iBAClC,CAAC,CAAA;YACN,CAAC;QACL,CAAC;QACD,OAAO,OAAO,CAAA;IAClB,CAAC;CACJ;AAvDD,oCAuDC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Contract instance wrapper for easy interaction
3
+ */
4
+ import { Demos } from '../websdk/demosclass';
5
+ import { ContractCallResult, ContractCallOptions, ContractABI } from './types/ContractABI';
6
+ import { ContractInstance as IContractInstance } from './types/TypedContract';
7
+ export declare class ContractInstance<T = any> implements IContractInstance<T> {
8
+ private demos;
9
+ address: string;
10
+ abi?: ContractABI;
11
+ private interactor;
12
+ methods: T;
13
+ constructor(demos: Demos, address: string, abi?: ContractABI);
14
+ /**
15
+ * Call a contract method
16
+ */
17
+ call<R = any>(method: string, args?: any[], options?: ContractCallOptions): Promise<ContractCallResult<R>>;
18
+ /**
19
+ * Send DEM with a contract call
20
+ */
21
+ callWithValue<R = any>(method: string, args: any[], value: bigint | number, options?: ContractCallOptions): Promise<ContractCallResult<R>>;
22
+ /**
23
+ * Get contract state (if accessible)
24
+ */
25
+ getState(key?: string): Promise<any>;
26
+ /**
27
+ * Get contract metadata
28
+ */
29
+ getMetadata(): Promise<any>;
30
+ /**
31
+ * Get contract events
32
+ */
33
+ getEvents(params?: {
34
+ eventName?: string;
35
+ fromBlock?: number;
36
+ toBlock?: number;
37
+ limit?: number;
38
+ }): Promise<any[]>;
39
+ /**
40
+ * Setup method proxies based on ABI
41
+ */
42
+ private setupMethodProxies;
43
+ /**
44
+ * Create a typed instance from ABI
45
+ */
46
+ static fromABI<T>(demos: Demos, address: string, abi: ContractABI): ContractInstance<T>;
47
+ /**
48
+ * Wait for contract to be deployed at address
49
+ */
50
+ static waitForDeployment(demos: Demos, address: string, timeout?: number): Promise<boolean>;
51
+ }
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ /**
3
+ * Contract instance wrapper for easy interaction
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ContractInstance = void 0;
7
+ const ContractInteractor_1 = require("./ContractInteractor");
8
+ class ContractInstance {
9
+ constructor(demos, address, abi) {
10
+ this.demos = demos;
11
+ this.address = address;
12
+ this.abi = abi;
13
+ this.methods = {};
14
+ this.interactor = new ContractInteractor_1.ContractInteractor(demos);
15
+ // Set up method proxies if ABI is provided
16
+ if (abi && abi.functions) {
17
+ this.setupMethodProxies();
18
+ }
19
+ // Set up general proxy for dynamic method calls
20
+ return new Proxy(this, {
21
+ get: (target, prop) => {
22
+ // Return existing properties
23
+ if (prop in target) {
24
+ return target[prop];
25
+ }
26
+ // Create dynamic method caller
27
+ if (typeof prop === 'string' && !prop.startsWith('_')) {
28
+ return (...args) => this.call(prop, args);
29
+ }
30
+ return undefined;
31
+ }
32
+ });
33
+ }
34
+ /**
35
+ * Call a contract method
36
+ */
37
+ async call(method, args = [], options) {
38
+ return await this.interactor.call(this.address, method, args, options);
39
+ }
40
+ /**
41
+ * Send DEM with a contract call
42
+ */
43
+ async callWithValue(method, args, value, options) {
44
+ return await this.call(method, args, {
45
+ ...options,
46
+ value
47
+ });
48
+ }
49
+ /**
50
+ * Get contract state (if accessible)
51
+ */
52
+ async getState(key) {
53
+ if (key) {
54
+ return await this.call('getState', [key]);
55
+ }
56
+ return await this.call('getState', []);
57
+ }
58
+ /**
59
+ * Get contract metadata
60
+ */
61
+ async getMetadata() {
62
+ const result = await this.demos.rpcCall({
63
+ method: 'getContractMetadata',
64
+ params: [this.address]
65
+ });
66
+ return result.result === 200 ? result.response : null;
67
+ }
68
+ /**
69
+ * Get contract events
70
+ */
71
+ async getEvents(params) {
72
+ const result = await this.demos.rpcCall({
73
+ method: 'getContractEvents',
74
+ params: [{
75
+ contractAddress: this.address,
76
+ ...params
77
+ }]
78
+ });
79
+ return result.result === 200 ? result.response.events : [];
80
+ }
81
+ /**
82
+ * Setup method proxies based on ABI
83
+ */
84
+ setupMethodProxies() {
85
+ if (!this.abi || !this.abi.functions)
86
+ return;
87
+ for (const func of this.abi.functions) {
88
+ if (func.visibility === 'public') {
89
+ this.methods[func.name] = async (...args) => {
90
+ // Validate argument count
91
+ const requiredParams = func.parameters.filter(p => !p.optional).length;
92
+ if (args.length < requiredParams) {
93
+ throw new Error(`Method ${func.name} expects at least ${requiredParams} arguments, got ${args.length}`);
94
+ }
95
+ // Determine if this is a view call
96
+ const isView = func.mutability === 'view' || func.mutability === 'pure';
97
+ const options = {};
98
+ if (func.mutability === 'payable' && args.length > func.parameters.length) {
99
+ // Last argument might be value
100
+ options.value = args.pop();
101
+ }
102
+ const result = await this.call(func.name, args, options);
103
+ if (result.success) {
104
+ return result.result;
105
+ }
106
+ else {
107
+ throw new Error(result.error || `Call to ${func.name} failed`);
108
+ }
109
+ };
110
+ }
111
+ }
112
+ }
113
+ /**
114
+ * Create a typed instance from ABI
115
+ */
116
+ static fromABI(demos, address, abi) {
117
+ return new ContractInstance(demos, address, abi);
118
+ }
119
+ /**
120
+ * Wait for contract to be deployed at address
121
+ */
122
+ static async waitForDeployment(demos, address, timeout = 30000) {
123
+ const startTime = Date.now();
124
+ while (Date.now() - startTime < timeout) {
125
+ const result = await demos.rpcCall({
126
+ method: 'getContract',
127
+ params: [address]
128
+ });
129
+ if (result.result === 200 && result.response) {
130
+ return true;
131
+ }
132
+ await new Promise(resolve => setTimeout(resolve, 1000));
133
+ }
134
+ return false;
135
+ }
136
+ }
137
+ exports.ContractInstance = ContractInstance;
138
+ //# sourceMappingURL=ContractInstance.js.map
@@ -0,0 +1 @@
1
+ {"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AC,IAAI,SAAS,CAAC,CAAA;oBAClE,CAAC;gBACL,CAAC,CAAA;YACL,CAAC;QACL,CAAC;IACL,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAO,CACV,KAAY,EACZ,OAAe,EACf,GAAgB;QAEhB,OAAO,IAAI,gBAAgB,CAAI,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,CAAA;IACvD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAC1B,KAAY,EACZ,OAAe,EACf,UAAkB,KAAK;QAEvB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAE5B,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,GAAG,OAAO,EAAE,CAAC;YACtC,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC;gBAC/B,MAAM,EAAE,aAAa;gBACrB,MAAM,EAAE,CAAC,OAAO,CAAC;aACb,CAAC,CAAA;YAET,IAAI,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;gBAC3C,OAAO,IAAI,CAAA;YACf,CAAC;YAED,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;QAC3D,CAAC;QAED,OAAO,KAAK,CAAA;IAChB,CAAC;CACJ;AArLD,4CAqLC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Contract interaction functionality for Demos SDK
3
+ */
4
+ import { Demos } from '../websdk/demosclass';
5
+ import { ContractCallResult, ContractCallOptions } from './types/ContractABI';
6
+ export declare class ContractInteractor {
7
+ private demos;
8
+ constructor(demos: Demos);
9
+ /**
10
+ * Call a smart contract method
11
+ * @param contractAddress The contract address
12
+ * @param method The method name to call
13
+ * @param args Arguments for the method
14
+ * @param options Call options
15
+ * @returns Call result
16
+ */
17
+ call<T = any>(contractAddress: string, method: string, args?: any[], options?: ContractCallOptions): Promise<ContractCallResult<T>>;
18
+ /**
19
+ * Batch multiple contract calls
20
+ */
21
+ batchCall(calls: Array<{
22
+ contractAddress: string;
23
+ method: string;
24
+ args: any[];
25
+ options?: ContractCallOptions;
26
+ }>): Promise<ContractCallResult[]>;
27
+ /**
28
+ * Read-only contract call (no transaction)
29
+ */
30
+ private viewCall;
31
+ /**
32
+ * State-changing contract call (sends transaction)
33
+ */
34
+ private transactionCall;
35
+ /**
36
+ * Build contract call transaction
37
+ */
38
+ private buildCallTransaction;
39
+ /**
40
+ * Check if a call is view/pure (read-only)
41
+ */
42
+ private isViewCall;
43
+ /**
44
+ * Wait for transaction confirmation
45
+ */
46
+ private waitForTransaction;
47
+ /**
48
+ * Helper to send RPC requests
49
+ */
50
+ private sendRPC;
51
+ /**
52
+ * Helper to sign transactions
53
+ */
54
+ private signTransaction;
55
+ }