0

I’m receiving then ex error: C:\Users\xxxxx\AppData\Roaming\npm\node_modules\truffle\build\commands.bundled.js:455204 throw new Error("Could not find artifacts for " + import_path + " from any sources");

I read a lot of answer a bout the error, but any works for me.

2_ContratoUsuarios_migration.js

const ContratoUsuarios = artifacts.require("ContratoUsuarios");

module.exports = function (deployer) { 
  deployer.deploy(ContratoUsuarios);
};

truffle_config.js

module.exports = {
  working_directory: "C:/Users/xxxxx/OneDrive/Udemy/Solidity/ethereum-truffle",
  contracts_directory: "./contracts",
  contracts_build_directory: "./build/contracts",
  networks: {
    development: {
      host: "127.0.0.1",     // Localhost (default: none)
      port: 7545,            // Standard Ethereum port (default: none)
      network_id: "*"       // Any network (default: none)
    },

    gas: 5000000,           // Gas sent with each transaction (default: ~6700000)
  },
  compilers: {
    solc: {
      version: "0.7.2",    // Fetch exact version from solc-bin (default: truffle's version)
      settings: {          // See the solidity docs for advice about optimization and evmVersion
        optimizer: {
          enabled: false,
          runs: 200
        },

      }
    },
  },
};

ContratoUsuarios.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.8.0;

contract ContratoUsuario {
    string public nombre;

    constructor() public {
        nombre = "Contrato de Usuarios";
    }

    struct Usuario {
        string sNombre;
        string sApellido;
    }
    mapping(address => Usuario) private Usuarios;
    mapping(address => bool) private UsuariosUnidos;
    address[] aUsuarios;

    event eUsuarioUnido(address, string);

    function Unirse(string memory cdNombre, string memory cdApellido) public {
        require(!UsuarioRegistrado(msg.sender));
        Usuario storage Usuario1 = Usuarios[msg.sender];
        Usuario1.sNombre = cdNombre;
        Usuario1.sApellido = cdApellido;
        UsuariosUnidos[msg.sender] = true;
        aUsuarios.push(msg.sender);
        emit eUsuarioUnido(msg.sender, string (abi.encodePacked(Usuario1.sNombre, " ", Usuario1.sApellido)));
    }

    function ObtenerUsuario(address Direccion) public view returns (string memory, string memory) {
        require(UsuarioRegistrado(msg.sender));
        Usuario memory Usuario1 = Usuarios[Direccion];
        return (Usuario1.sNombre, Usuario1.sApellido);
    }

    function UsuarioRegistrado(address Direccion) private view returns (bool) {
        return UsuariosUnidos[Direccion];
    }

    function UsuariosTotales() public view returns (uint) {
        return aUsuarios.length;
    }

}

The command executed and the error:

PS C:\Users\xxxxx\OneDrive\Udemy\Solidity\ethereum-truffle> truffle migrate --reset

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.



Starting migrations...
======================
> Network name:    'development'
> Network id:      5777
> Block gas limit: 6721975 (0x6691b7)


1_initial_migration.js
======================

   Replacing 'Migrations'
   ----------------------
   > transaction hash:    0xcb0612ff71ba3bb930cfa3bdf73c5fe0651ed58d35523bf268e261bf2c03740e
   > Blocks: 0            Seconds: 0
   > contract address:    0x1d75F14dde09664c6d7B9C70B6F1D1787BF056bf
   > block number:        51
   > block timestamp:     1603060864
   > account:             0x29025b199573254417451276b7fD0BC7e54B90b0
   > balance:             199.88161174
   > gas used:            186963 (0x2da53)
   > gas price:           20 gwei
   > value sent:          0 ETH
   > total cost:          0.00373926 ETH


   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:          0.00373926 ETH


2_ContratoUsuarios_migration.js
===============================

C:\Users\xxxxx\AppData\Roaming\npm\node_modules\truffle\build\commands.bundled.js:455204
        throw new Error("Could not find artifacts for " + import_path + " from any sources");
        ^

I add the folder structure: enter image description here

Versions of software that I,m using:

Solidity 0.7.2
Node v12.18.4
Truffle v5.1.49 (core: 5.1.49) 
npm 6.14.8
web3 1.3.0

I tried all the answer that I found on internet but any one works. Can somobody help me?

Thanks in advanced and have a nice week.

  • 1
    Check that the name of the contract (ContratoUsuario) is not the same as the name of the file (ContratoUsuarios). – alberto Oct 20 at 12:11
  • You're right Alberto, but ContratoUsuario.json is made by truffle when it compile ContratoUsuarios.sol. I deleted it many times, I deleted the folder and truffle create ContratoUsuario.json, Why?. Thanks and have a nice week. – abiurrunc Oct 20 at 19:53
  • Yes, but see the line: contract ContratoUsuario {. Have you tried changing into contract ContratoUsuarios {? – alberto Oct 20 at 20:04
  • Alberto, you were right, I didn't see it. Many, many thanks. – abiurrunc Oct 20 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.