I am trying to deploy a simple contract using truffle on my local Geth network. But it is throwing the following error:
Santanu@ITS-7 MINGW64 /d/xampp/htdocs/truffle_nft_example_nuxt (main)
> Blocks: 1 Seconds: 17
> contract address: 0x23Fc1181846184eb761C46FBDFC422540C3b5818
> block number: 695l D:\xampp\htdocs\truffle_nft_example_nuxt
> block timestamp: 1627545708ent --reset
> account: 0x6D2b5befcc6f0eDbEcED06EAE3942e9A2064Bed3
> balance: 100000003475
> gas used: 290518 (0x46ed6)
> gas price: 1 gwei
> value sent: 0 ETHre is nothing to compile.
> total cost: 0.000290518 ETH
Pausing for 2 confirmations...
------------------------------
> confirmation number: 1 (block: 696)
> confirmation number: 2 (block: 697)
> Network id: 1234
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0.000290518 ETH
======================
2_artwork_minter_migration.js
=============================
> transaction hash: 0x48d2197e66e78e4c87a6350b17ae9506ded7aae888d092ecc6d42af28757f865
Deploying 'ProxyAdmin'
----------------------
> transaction hash: 0xb3fc6546823255be643d4b19abce89c0c02b6853c8e1986e655f823ef2f5706a
Error: *** Deployment Failed ***
"ProxyAdmin" hit an invalid opcode while deploying. Try:
* Verifying that your constructor params satisfy all assert conditions.
* Verifying your constructor code doesn't access an array out of bounds.
* Adding reason strings to your assert statements.
at C:\Users\Santanu\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\deployer\src\deployment.js:365:1
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at Object.deploy (D:\xampp\htdocs\truffle_nft_example_nuxt\node_modules\@openzeppelin\truffle-upgrades\src\utils\deploy.ts:9:48)
at Object.resumeOrDeploy (D:\xampp\htdocs\truffle_nft_example_nuxt\node_modules\@openzeppelin\upgrades-core\src\deployment.ts:42:22)
at D:\xampp\htdocs\truffle_nft_example_nuxt\node_modules\@openzeppelin\upgrades-core\src\impl-store.ts:33:23
at Manifest.lockedRun (D:\xampp\htdocs\truffle_nft_example_nuxt\node_modules\@openzeppelin\upgrades-core\src\manifest.ts:118:14)
at fetchOrDeployGeneric (D:\xampp\htdocs\truffle_nft_example_nuxt\node_modules\@openzeppelin\upgrades-core\src\impl-store.ts:25:24)
at deployProxy (D:\xampp\htdocs\truffle_nft_example_nuxt\node_modules\@openzeppelin\truffle-upgrades\src\deploy-proxy.ts:59:28)
at module.exports (D:\xampp\htdocs\truffle_nft_example_nuxt\migrations\2_artwork_minter_migration.js:6:3)
at Migration._deploy (C:\Users\Santanu\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:80:1)
at Migration._load (C:\Users\Santanu\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:61:1)
at Migration.run (C:\Users\Santanu\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:218:1)
at Object.runMigrations (C:\Users\Santanu\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:150:1)
at Object.runFrom (C:\Users\Santanu\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:110:1)
at Object.runAll (C:\Users\Santanu\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:114:1)
at Object.run (C:\Users\Santanu\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:79:1)
at runMigrations (C:\Users\Santanu\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:258:1)
at Object.run (C:\Users\Santanu\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:223:1)
at Command.run (C:\Users\Santanu\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\command.js:167:1)
Truffle v5.4.0 (core: 5.4.0)
Node v12.19.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nuxt_app@ fresh-deploy-local: `truffle migrate --network development --reset`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nuxt_app@ fresh-deploy-local script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Santanu\AppData\Roaming\npm-cache\_logs\2021-07-29T08_02_33_234Z-debug.log
Here is my migration file:
const colors = require('colors');
const ArtWorkMinter = artifacts.require('ArtWorkMinter');
const { deployProxy } = require('@openzeppelin/truffle-upgrades');
module.exports = async deployer => {
await deployProxy(ArtWorkMinter, { deployer, initializer: 'initialize' });
}
And here is the full implementation of the contract:
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol";
contract ArtWorkMinter is ERC721Upgradeable, OwnableUpgradeable, ReentrancyGuardUpgradeable{
struct TokenMeta {
uint256 id;
string name;
uint256 price;
bool sale;
string uri;
}
string baseURI;
mapping(uint256 => TokenMeta) private _tokenMeta;
using CountersUpgradeable for CountersUpgradeable.Counter;
CountersUpgradeable.Counter private _tokenIds;
function initialize() public initializer {
OwnableUpgradeable.__Ownable_init();
ReentrancyGuardUpgradeable.__ReentrancyGuard_init();
ERC721Upgradeable.__ERC721_init("ArtWorkMinter", "ArtWorkMinter");
setBaseURI("https://rh25q24tvf.execute-api.eu-west-2.amazonaws.com/dev/token?id=");
}
function _baseURI() internal view override virtual returns (string memory) {
return baseURI;
}
function setBaseURI(string memory _newBaseURI) public virtual onlyOwner {
baseURI = _newBaseURI;
}
function getAllOnSale () public view virtual returns( TokenMeta[] memory ) {
TokenMeta[] memory tokensOnSale = new TokenMeta[](_tokenIds.current());
uint256 counter = 0;
for(uint i = 1; i < _tokenIds.current() + 1; i++) {
if(_tokenMeta[i].sale == true) {
tokensOnSale[counter] = _tokenMeta[i];
counter++;
}
}
return tokensOnSale;
}
function setTokenSale(uint256 _tokenId, bool _sale, uint256 _price) public {
require(_exists(_tokenId), "ERC721Metadata: Sale set of nonexistent token");
require(_price > 0);
require(ownerOf(_tokenId) == _msgSender());
_tokenMeta[_tokenId].sale = _sale;
setTokenPrice(_tokenId, _price);
}
function setTokenPrice(uint256 _tokenId, uint256 _price) public {
require(_exists(_tokenId), "ERC721Metadata: Price set of nonexistent token");
require(ownerOf(_tokenId) == _msgSender());
_tokenMeta[_tokenId].price = _price;
}
function tokenPrice(uint256 tokenId) public view virtual returns (uint256) {
require(_exists(tokenId), "ERC721Metadata: Price query for nonexistent token");
return _tokenMeta[tokenId].price;
}
function _setTokenMeta(uint256 _tokenId, TokenMeta memory _meta) private {
require(_exists(_tokenId));
require(ownerOf(_tokenId) == _msgSender());
_tokenMeta[_tokenId] = _meta;
}
function tokenMeta(uint256 _tokenId) public view returns (TokenMeta memory) {
require(_exists(_tokenId));
return _tokenMeta[_tokenId];
}
function purchaseToken(uint256 _tokenId) public payable nonReentrant {
require(msg.sender != address(0) && msg.sender != ownerOf(_tokenId));
require(msg.value >= _tokenMeta[_tokenId].price);
address tokenSeller = ownerOf(_tokenId);
payable(tokenSeller).transfer(msg.value);
setApprovalForAll(tokenSeller, true);
_transfer(tokenSeller, msg.sender, _tokenId);
_tokenMeta[_tokenId].sale = false;
}
function mint_art_work(address receiver, string memory tokenURI, string memory name, uint256 price, bool sale) public onlyOwner returns (uint256) {
require(price > 0);
_tokenIds.increment();
uint256 newNftTokenId = _tokenIds.current();
_mint(receiver, newNftTokenId);
TokenMeta memory meta = TokenMeta(newNftTokenId, name, price, sale, tokenURI);
_setTokenMeta(newNftTokenId, meta);
return newNftTokenId;
}
function get_token_details(uint token_id) external view returns (string memory){
return tokenURI(token_id);
}
}
Note that If I deploy this on Rinkeby network, it goes successfully. But on local Geth network, it gives me this problem.
Any help would be really appriciated. Thank you.