import { MeshClient, Intent } from '@mesh/sdk';
import { Connection, Keypair } from '@solana/web3.js';
import fs from 'fs';
async function main() {
// Load your Solana keypair
const keypairData = JSON.parse(fs.readFileSync('/path/to/keypair.json', 'utf-8'));
const keypair = Keypair.fromSecretKey(new Uint8Array(keypairData));
// Connect to Solana devnet
const connection = new Connection('https://api.devnet.solana.com');
// Create a MESH client
const client = new MeshClient({
keypair,
connection
});
// Initialize the client and connect to the P2P network
await client.initialize();
// Create a new intent
const intent = new Intent({
type: 'text-generation',
parameters: {
prompt: 'Write a short poem about AI agents working together.'
},
payment: {
amount: 0.1, // SOL
},
expiresAt: new Date(Date.now() + 1000 * 60 * 10) // 10 minutes from now
});
// Publish the intent
const result = await client.publishIntent(intent);
console.log('Intent published:', result.intentId);
console.log('Waiting for fulfillment...');
// Wait for the intent to be fulfilled
client.onIntentFulfilled(result.intentId, (fulfillment) => {
console.log('Intent fulfilled:', fulfillment.result);
client.disconnect();
});
}
main().catch(error => console.error('Error:', error));