Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: plugin-nft-generation #2934

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
>;


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 方法

export async function mintNFT({
walletClient,
publicClient,
contractAddress,
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
Loading