Get Started
Get Started with Dialect AI
Learn how to get set up and start using the Dialect AI API to interpret natural language and execute blockchain transactions—such as signing and sending a transfer—using smart, connected agents.
Prerequisites
Before you begin, ensure you have the following ready:
A Dialect AI account
A blockchain wallet (e.g., MetaMask) for signing and executing transactions
Node.js and either npm or yarn installed on your system
Step 1: Obtain API Credentials
Create a Project
Log in to your Dialect AI Dashboard and create a new project. Each project provides a Client ID and a Secret Key.
Save Your Keys
After your project is created, securely store your Secret Key—it will not be retrievable later.
Client ID vs Secret Key
Client ID Public-facing identifier, safe to use on the frontend. It is restricted by the domain settings you configure in your API dashboard.
Secret Key Used for backend scripts and server-side requests. Never expose your Secret Key in frontend code.
Step 2: Install the SDK
Install the Dialect AI TypeScript SDK using npm:
bashCopyEditnpm install @dialectai/sdkStep 3: Set Environment Variables
Add your Secret Key to your project’s environment configuration.
💡 Use a secure secrets manager like AWS Secrets Manager or Google Secret Manager for production deployments.
bashCopyEditDIALECT_SECRET_KEY=your_dialect_secret_keyStep 4: Import SDK Functions
Import necessary utilities from the Dialect AI SDK:
tsCopyEditimport {
createDialectClient,
prepareTransaction,
sendTransaction,
privateKeyToAccount,
} from "@dialectai/sdk";Step 5: Handle API Response & Execute a Transaction
This function takes the response from the Dialect AI API and executes the parsed transaction using your wallet.
tsCopyEditimport { generateAccount } from "@dialectai/sdk/wallets";
async function handleDialectResponse(response) {
const client = createDialectClient({
secretKey: process.env.DIALECT_SECRET_KEY,
});
const account = await generateAccount({ client });
if (response.actions && response.actions.length > 0) {
const action = response.actions[0];
const txData = JSON.parse(action.data);
try {
const transaction = prepareTransaction({
to: txData.to,
data: txData.data,
value: BigInt(txData.value),
chain: txData.chainId,
client,
});
const result = await sendTransaction({
transaction,
account,
});
console.log("Transaction Successful:", result);
return result;
} catch (error) {
console.error("Error executing transaction:", error);
throw error;
}
}
}Step 6: Call the Dialect AI API
Send a natural language instruction to the API to generate a blockchain transaction:
tsCopyEditconst response = await fetch("https://api.dialectai.com/chat", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-secret-key": process.env.DIALECT_SECRET_KEY,
},
body: JSON.stringify({
message: "send 0.001 ETH on Sepolia to vitalik.eth",
execute_config: {
mode: "client",
signer_wallet_address: "0xYourWalletAddress",
},
}),
});
const data = await response.json();
await handleDialectResponse(data);Example API Response
jsonCopyEdit{
"transactionHash": "0x123abc...",
"blockNumber": 1234567,
...
}✅ You’re All Set!
You've now successfully integrated the Dialect AI API and executed your first transaction using a natural language prompt. Next, explore how to create multi-step workflows, plug into LangChain, or build autonomous agents that reason about blockchain data.
Last updated