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

introduction-to-ethereum-swarm/08-mint-nft - feedback #8

Open
Kexort opened this issue Jan 18, 2024 · 0 comments
Open

introduction-to-ethereum-swarm/08-mint-nft - feedback #8

Kexort opened this issue Jan 18, 2024 · 0 comments

Comments

@Kexort
Copy link

Kexort commented Jan 18, 2024

Problem:

The tests of the 'Introduction to Ethereum Swarm 8. Mint NFT' course cannot run because of the following error:

Wrong solution!
Should correctly mint NFT
Error: Cannot find module '@agorapp/contracts' Require stack: - /app/packages/swarm-docker-runner/userspace/code/main.ts - /app/packages/runner-common/src/services/JavaScriptUserspace.ts - /app/packages/runner-common/src/index.ts - /app/packages/swarm-docker-runner/src/modules/courses/introToSwarm.ts - /app/packages/swarm-docker-runner/src/main.ts

My code:

import { Bee } from '@ethersphere/bee-js';
import { NftContractWrapper } from '@agorapp/contracts';

const bee = new Bee('https://api.gateway.ethswarm.org');

export async function main(
  nftFaucetContractAddress: string,
  imgPostageStampId: string,
  imgFile: string,
  postageStampId: string,
  recipient: string,
) {
  
  await uploadNftImage(imgPostageStampId, imgFile)
  await prepareNftMetadata(imgPostageStampId, imgFile)
  const nftFaucetContract = new NftContractWrapper(nftFaucetContractAddress);
  const imgUri = await uploadNftImage(imgPostageStampId, imgFile);
  const tokenUri = await prepareNftMetadata(postageStampId, imgUri);

  const mintedTx = await nftFaucetContract.mintNft(recipient, tokenUri);
  return {transactionHash: mintedTx.transactionHash};
}

export async function uploadNftImage(imgPostageStampId: string, imgFile: string) {
  const res = await bee.uploadFile(imgPostageStampId, imgFile);
  return 'bzz://'.concat(res.reference);
}

export async function prepareNftMetadata(postageStampId: string, imgUri: string) {
  const metadata = {
    name: 'My NFT',
    description: 'My NFT description',
    image: imgUri,
  };

  const metadataStr = JSON.stringify(metadata);

  const res = await bee.uploadData(postageStampId, metadataStr);

  return {
    reference: res.reference,
    tokenUri: 'bzz://'.concat(res.reference),
  };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant