Skip to content

Commit 6134b87

Browse files
superoo70xaguspunk
andauthored
Chr wallet check (#65)
* add wallet check logic * add changelog * clean up with linting * Update tame-tomatoes-doubt.md * add receipt tx and attach explorer link --------- Co-authored-by: Agus <[email protected]>
1 parent cdaa58e commit 6134b87

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@goat-sdk/wallet-chromia": patch
3+
---
4+
5+
Add wallet check before send

typescript/examples/vercel-ai/chromia/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ if (!privateKey) {
4242
model: openai("gpt-4o-mini"),
4343
tools: tools,
4444
maxSteps: 5,
45-
prompt: "send 0.0001 CHR to <recipient address>",
45+
prompt: "send 0.0001 CHR to <recipient_address>, and please attach the transaction explorer link",
4646
});
4747

4848
console.log(result.text);

typescript/packages/core/src/core-plugins/send-chr.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { z } from "zod";
22
import type { Plugin } from "../plugins";
33
import type { Chain, ChromiaWalletClient } from "../wallets";
44

5+
export enum CHROMIA_MAINNET_BRID {
6+
ECONOMY_CHAIN = "15C0CA99BEE60A3B23829968771C50E491BD00D2E3AE448580CD48A8D71E7BBA",
7+
}
58
export const CHR_ASSET_ID = "5f16d1545a0881f971b164f1601cbbf51c29efd0633b2730da18c403c3b428b5";
69

710
export function sendCHR(): Plugin<ChromiaWalletClient> {
@@ -34,8 +37,8 @@ async function sendCHRMethod(
3437
): Promise<string> {
3538
try {
3639
const { to, amount } = parameters;
37-
await walletClient.sendTransaction({ to, assetId: CHR_ASSET_ID, amount });
38-
return `CHR sent to ${to} with amount ${amount}`;
40+
const { receipt } = await walletClient.sendTransaction({ to, assetId: CHR_ASSET_ID, amount });
41+
return `https://explorer.chromia.com/mainnet/${CHROMIA_MAINNET_BRID.ECONOMY_CHAIN}/transaction/${receipt.transactionRid.toString("hex")}`;
3942
} catch (error) {
4043
return `Error sending CHR: ${error}`;
4144
}

typescript/packages/wallets/chromia/src/index.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
type Connection,
3-
type KeyStoreInteractor,
4-
Session,
5-
createAmount,
6-
createInMemoryFtKeyStore,
7-
createKeyStoreInteractor,
8-
} from "@chromia/ft4";
1+
import { type Connection, type KeyStoreInteractor, createAmount } from "@chromia/ft4";
92
import { type DictPair, type IClient, type QueryObject, type RawGtv, SignatureProvider } from "postchain-client";
103

114
export enum CHROMIA_MAINNET_BRID {
@@ -41,6 +34,9 @@ export function chromia({ client, keystoreInteractor, accountAddress, connection
4134
return { signature: "" };
4235
},
4336
async sendTransaction({ to, assetId, amount }: ChromiaTransaction) {
37+
if (!to.match(/^[a-f0-9]{64}$/i)) {
38+
throw new Error("Invalid Address");
39+
}
4440
const accounts = await keystoreInteractor.getAccounts();
4541
const session = await keystoreInteractor.getSession(accounts[0].id);
4642
const asset = await connection.getAssetById(assetId);

0 commit comments

Comments
 (0)