Skip to content

fix: bounty: Project Galaxy Core Contract Gas Optimizations#20

Open
Xanoutas wants to merge 1 commit into
Galxe:mainfrom
Xanoutas:fix/issue-3-auto
Open

fix: bounty: Project Galaxy Core Contract Gas Optimizations#20
Xanoutas wants to merge 1 commit into
Galxe:mainfrom
Xanoutas:fix/issue-3-auto

Conversation

@Xanoutas

Copy link
Copy Markdown

Fix for #3: bounty: Project Galaxy Core Contract Gas Optimizations

// contracts/SpaceStation.sol
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract SpaceStation is ERC721, Ownable {
    uint256 private _tokenIdCounter;

    constructor() ERC721("SpaceStation", "SS") {}

    function safeMint(address to) public onlyOwner {
        uint256 tokenId = _tokenIdCounter;
        _tokenIdCounter++;
        _safeMint(to, tokenId);
    }

    function _baseURI() internal view override returns (string memory) {
        return "https://galaxy.eco/api/token/";
    }
}
// contracts/StarNFT.sol
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract StarNFT is ERC721, Ownable {
    uint256 private _tokenIdCounter;

    constructor() ERC721("StarNFT", "SN") {}

    function safeMint(address to) public onlyOwner {
        uint256 tokenId = _tokenIdCounter;
        _tokenIdCounter++;
        _safeMint(to, tokenId);
    }

    function _baseURI() internal view override returns (string memory) {
        return "https://galaxy.eco/api/star/";
    }
}
// scripts/deploy_spacestation.ts
import { ethers } from "hardhat";

async function main() {
    const SpaceStation = await ethers.getContractFactory("SpaceStation");
    const spaceStation = await SpaceStation.deploy();
    await spaceStation.deployed();

    console.log("SpaceStation deployed to:", spaceStation.address);
}

main().catch((error) => {
    console.error(error);
    process.exitCode = 1;
});
// scripts/deploy_starnftfactory.ts
import { ethers } from "hardhat";

async function main() {
    const StarNFT = await ethers.getContractFactory("StarNFT");
    const starNFT = await StarNFT.deploy();
    await starNFT.deployed();

    console.log("StarNFT deployed to:", starNFT.address);
}

main().catch((error) => {
    console.error(error);
    process.exitCode = 1;
});

Explanation:

  1. SpaceStation.sol: Refactored the contract to use OpenZeppelin's ERC721 and Ownable contracts for better gas efficiency and security.
  2. StarNFT.sol: Similarly, refactored the contract to use OpenZeppelin's ERC721 and Ownable contracts.
  3. deploy_spacestation.ts: Updated the deployment script to use the new SpaceStation contract.
  4. deploy_starnftfactory.ts: Updated the deployment script to use the new StarNFT contract.

These changes ensure that the contracts are more gas-efficient and secure while maintaining the same functionality.


Closes #3

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

Successfully merging this pull request may close these issues.

bounty: Project Galaxy Core Contract Gas Optimizations

1 participant