Giter Site home page Giter Site logo

Comments (2)

mucademarchi avatar mucademarchi commented on July 3, 2024
<title>NFT Marketplace</title> <style> /* Estilos básicos para o marketplace */ body { font-family: Arial, sans-serif; margin: 0; padding: 20px; }
    h1 {
        margin-bottom: 20px;
    }
    
    .nft-card {
        border: 1px solid #ccc;
        border-radius: 4px;
        padding: 10px;
        margin-bottom: 10px;
    }
    
    .nft-card img {
        width: 100%;
        max-height: 200px;
        object-fit: cover;
        border-radius: 4px;
    }
    
    .nft-card h3 {
        margin-top: 10px;
    }
    
    .nft-card p {
        margin-top: 5px;
        font-size: 14px;
        color: #888;
    }
    
    .create-form {
        margin-bottom: 20px;
    }
    
    .create-form input {
        margin-right: 10px;
    }
</style>

NFT Marketplace

<div class="create-form">
    <h3>Create NFT</h3>
    <input type="text" id="nftName" placeholder="NFT Name">
    <input type="number" id="listingPrice" placeholder="Listing Price">
    <button onclick="createNFT()">Create</button>
</div>

<div id="nftList"></div>

<script>
    // Endereço do contrato inteligente
    const contractAddress = "YOUR_CONTRACT_ADDRESS";
    
    // Objeto Web3
    let web3;
    
    // Função para criar um NFT
    async function createNFT() {
        const nftName = document.getElementById("nftName").value;
        const listingPrice = document.getElementById("listingPrice").value;
        
        // Valide os campos aqui se necessário
        
        const accounts = await web3.eth.requestAccounts();
        const account = accounts[0];
        
        const contract = new web3.eth.Contract(contractABI, contractAddress);
        await contract.methods.createNFT(nftName).send({ from: account, value: web3.utils.toWei(listingPrice, "ether") });
        
        // Atualize a lista de NFTs após a criação bem-sucedida
        fetchNFTs();
    }
    
    // Função para buscar e exibir NFTs
    async function fetchNFTs() {
        const contract = new web3.eth.Contract(contractABI, contractAddress);
        const totalSupply = await contract.methods.totalSupply().call();
        
        const nftListElement = document.getElementById("nftList");
        nftListElement.innerHTML = "";
        
        for (let i = 1; i <= totalSupply; i++) {
            const nft = await contract.methods.nfts(i).call();
            const owner = await contract.methods.ownerOf(i).call();
            
            const nftCard = document.createElement("div");
            nftCard.classList.add("nft-card");
            
            const image = document.createElement("img");
            image.src = "NFT_IMAGE_URL/" + nft.id + ".jpg";  // Insira a URL da imagem do NFT aqui
            nftCard.appendChild(image);
            
            const name = document.createElement("h3");
            name.textContent = nft.name;
            nftCard.appendChild(name);
            
            const ownerText = document.createElement("p");
            ownerText.textContent = "Owner: " + owner;
            nftCard.appendChild(ownerText);
            
            nftListElement.appendChild(nftCard);
        }
    }
    
    // Função para inicializar o Web3 e buscar os NFTs
    async function init() {
        if (typeof window.ethereum !== 'undefined') {
            web3 = new Web3(window.ethereum);
            await window.ethereum.enable();
        } else {
            console.log("Metamask não detectado");
        }
        
        fetchNFTs();
    }
    
    // Execute a função de inicialização
    init();
</script>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>
<script src="YOUR_CONTRACT_ABI.js"></script>  <!-- Insira o arquivo do ABI do seu contrato aqui -->

from developer.

trilloc avatar trilloc commented on July 3, 2024

good idea but the chatgpt plus allows only 25 messages in three hours... that wont be enough for most applications.

from developer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.