67 lines
1.6 KiB
Markdown
67 lines
1.6 KiB
Markdown
# @dbis-thirdweb/ai
|
|
|
|
Chain-aware AI prompts and actions for Chain 138.
|
|
|
|
## Usage
|
|
|
|
### Prompt Generation
|
|
|
|
```typescript
|
|
import { createReadPrompt, createWritePrompt, validatePromptForChain138 } from '@dbis-thirdweb/ai';
|
|
|
|
// Create read prompt
|
|
const readPrompt = createReadPrompt('getBalance', { address: '0x...' });
|
|
|
|
// Create write prompt
|
|
const writePrompt = createWritePrompt('transferNative', {
|
|
to: '0x...',
|
|
amount: '1000000000000000000', // 1 ETH in wei
|
|
});
|
|
|
|
// Validate prompt targets Chain 138
|
|
validatePromptForChain138(userPrompt);
|
|
```
|
|
|
|
### Read Actions
|
|
|
|
```typescript
|
|
import {
|
|
createReadBalanceAction,
|
|
createReadBlockHeightAction,
|
|
executeReadAction,
|
|
} from '@dbis-thirdweb/ai';
|
|
import { ThirdwebSDK } from '@thirdweb-dev/sdk';
|
|
import { chain138 } from '@dbis-thirdweb/chain';
|
|
|
|
const sdk = new ThirdwebSDK(chain138);
|
|
const provider = sdk.getProvider();
|
|
|
|
// Create action
|
|
const action = createReadBalanceAction('0x...');
|
|
|
|
// Execute
|
|
const result = await executeReadAction(action, sdk, provider);
|
|
console.log(result); // { address, balance, balanceFormatted }
|
|
```
|
|
|
|
### Write Actions
|
|
|
|
```typescript
|
|
import { createTransferAction, executeWriteAction } from '@dbis-thirdweb/ai';
|
|
|
|
// Create transfer action
|
|
const action = createTransferAction('0x...', '1000000000000000000');
|
|
|
|
// Execute (requires signer)
|
|
const result = await executeWriteAction(action, sdk);
|
|
console.log(result); // { txHash, chainId }
|
|
```
|
|
|
|
## Features
|
|
|
|
- Chain-aware prompt templates with Chain 138 guardrails
|
|
- Read action templates (balance, block height, token info)
|
|
- Write action templates (transfers, contract interactions)
|
|
- Chain ID routing validation
|
|
- Error handling for unsupported operations
|