Skip to content

Commit

Permalink
Merge pull request #2934 from AIFlowML/fix-plugin-nft-generation
Browse files Browse the repository at this point in the history
fix: plugin-nft-generation
  • Loading branch information
shakkernerd authored Jan 29, 2025
2 parents cf26e0f + f90f802 commit 5c69c8c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 16 deletions.
21 changes: 15 additions & 6 deletions packages/plugin-nft-generation/src/actions/mintNFTAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const _SupportedChainList = Object.keys(viemChains) as Array<
keyof typeof viemChains
>;


Check warning on line 27 in packages/plugin-nft-generation/src/actions/mintNFTAction.ts

View check run for this annotation

codefactor.io / CodeFactor

packages/plugin-nft-generation/src/actions/mintNFTAction.ts#L27

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
function isMintNFTContent(content: any): content is MintNFTContent {
return typeof content.collectionAddress === "string" && typeof content.collectionAddress === "string";
}
Expand Down Expand Up @@ -68,19 +69,27 @@ const mintNFTAction: Action = {
runtime: IAgentRuntime,
message: Memory,
state: State,
options: { [key: string]: unknown },
_options: { [key: string]: unknown },
callback: HandlerCallback
) => {
try {
elizaLogger.log("Composing state for message:", message);

// if (!state) {
// state = (await runtime.composeState(message)) as State;
// } else {
// state = await runtime.updateRecentMessageState(state);
// }

let currentState: State;
if (!state) {
state = (await runtime.composeState(message)) as State;
currentState = (await runtime.composeState(message)) as State;
} else {
state = await runtime.updateRecentMessageState(state);
currentState = await runtime.updateRecentMessageState(state);
}

const context = composeContext({
state,
state: currentState,
template: mintNFTTemplate,
});

Expand Down Expand Up @@ -229,7 +238,7 @@ const mintNFTAction: Action = {
}
}
return [];
} catch (e: any) {
} catch (e: unknown) {
elizaLogger.log(e);
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ const nftCollectionGeneration: Action = {
handler: async (
runtime: IAgentRuntime,
message: Memory,
state: State,
options: { [key: string]: unknown },
_state: State,
_options: { [key: string]: unknown },
callback: HandlerCallback
) => {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export async function createCollectionMetadata({
elizaLogger.log("User ID:", userId);
const awsS3Service: AwsS3Service = runtime.getService(ServiceType.AWS_S3);
const agentName = runtime.character.name;
const roomId = stringToUuid("nft_generate_room-" + agentName);
// const roomId = stringToUuid("nft_generate_room-" + agentName);
const roomId = stringToUuid(`nft_generate_room-${agentName}`);
// Create memory for the message
const memory: Memory = {
agentId: userId,
Expand Down Expand Up @@ -61,7 +62,7 @@ export async function createCollectionMetadata({
);
if (images.success && images.data && images.data.length > 0) {
const image = images.data[0];
const filename = `collection-image`;
const filename = 'collection-image';
if (image.startsWith("http")) {
elizaLogger.log("Generating image url:", image);
}
Expand Down
11 changes: 10 additions & 1 deletion packages/plugin-nft-generation/src/utils/deployEVMContract.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { encodeAbiParameters } from "viem";
import type {
Address,
WalletClient,
PublicClient,
Hash,
Abi
} from 'viem';
import { compileWithImports } from "./generateERC721ContractCode.ts";
import CustomERC721 from "../contract/CustomERC721.sol"

Expand Down Expand Up @@ -39,18 +46,20 @@ export async function deployContract({
}

// 调用 mint 方法

Check warning on line 49 in packages/plugin-nft-generation/src/utils/deployEVMContract.ts

View check run for this annotation

codefactor.io / CodeFactor

packages/plugin-nft-generation/src/utils/deployEVMContract.ts#L49

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
export async function mintNFT({
walletClient,

Check warning on line 51 in packages/plugin-nft-generation/src/utils/deployEVMContract.ts

View check run for this annotation

codefactor.io / CodeFactor

packages/plugin-nft-generation/src/utils/deployEVMContract.ts#L51

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
publicClient,
contractAddress,

Check warning on line 53 in packages/plugin-nft-generation/src/utils/deployEVMContract.ts

View check run for this annotation

codefactor.io / CodeFactor

packages/plugin-nft-generation/src/utils/deployEVMContract.ts#L53

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
abi,
recipient,
}: {
contractAddress: any;
contractAddress: string;
abi: any;
recipient: any;
walletClient: any;
publicClient: any;

}) {
console.log("Minting NFT...");
const txHash = await walletClient.writeContract({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import solc from "solc";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";

// Load OpenZeppelin contract source code
export function loadOpenZeppelinFile(contractPath) {
Expand Down Expand Up @@ -45,7 +45,9 @@ export function compileWithImports(contractName, sourceCode) {
);

if (output.errors) {
output.errors.forEach((err) => console.error(err));
for (const err of output.errors) {
console.error(err);
}
}
const contractFile = output.contracts[`${contractName}.sol`][`${contractName}`];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import {
loadOpenZeppelinFile,
} from "./generateERC721ContractCode.ts";

interface VerificationStatus {
result: string;
status?: string;
message?: string;
}

function getSources(metadata, sourceCode) {
const fileName = Object.keys(metadata.settings.compilationTarget)[0]
const obj = {
Expand Down Expand Up @@ -69,7 +75,7 @@ export async function verifyEVMContract({
};

// Poll for completion
let status;
let status: VerificationStatus;
do {
await new Promise((resolve) => setTimeout(resolve, 3000));
status = await checkStatus();
Expand Down

0 comments on commit 5c69c8c

Please sign in to comment.