Reputation: 1
I am trying to deploy a smart contract on the ethereum sepolia testnet in Remix IDE. But I'm getting the error "contract creation code storage out of gas". I do not understand the reason for this, since I have enough testnet ETH in my wallet, and I have only imported the necessary libraries. Here is the full code:
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
contract IssueCred is ERC20, AccessControl {
bytes32 public constant DOCTOR_ROLE = keccak256("DOCTOR_ROLE");
bytes32 public constant PHARMACIST_ROLE = keccak256("PHARMACIST_ROLE");
bytes32 public constant GOVERNMENT_ROLE = keccak256("GOVERNMENT_ROLE");
struct HealthCareProvider {
string name;
string licenseNumber;
bool isVerified;
}
struct Prescription {
address doctor;
string drug;
uint dosage;
uint duration;
uint timestamp;
}
mapping(address => HealthCareProvider) public providers;
mapping(string => Prescription[]) private prescriptions;
event ProviderRegistered(address indexed providerAddress, string name, string licenseNumber);
event ProviderVerified(address indexed providerAddress);
event PrescriptionIssued(address indexed doctor, string indexed patientID, string drug, uint dosage, uint duration);
constructor() ERC20("AccountabilityToken", "PHARMA") {
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(GOVERNMENT_ROLE, msg.sender);
_mint(msg.sender, 1000 * (10 ** decimals()));
}
function registerProvider(
address providerAddress,
string calldata name,
string calldata licenseNumber,
bytes32 role
) external onlyRole(GOVERNMENT_ROLE) {
require(role == DOCTOR_ROLE || role == PHARMACIST_ROLE, "Invalid role");
providers[providerAddress] = HealthCareProvider({
name: name,
licenseNumber: licenseNumber,
isVerified: false
});
emit ProviderRegistered(providerAddress, name, licenseNumber);
}
function verifyProvider(address providerAddress, bytes32 role) external onlyRole(GOVERNMENT_ROLE) {
require(providers[providerAddress].isVerified == false, "Provider already verified");
providers[providerAddress].isVerified = true;
_grantRole(role, providerAddress);
emit ProviderVerified(providerAddress);
}
function isProviderVerified(address providerAddress) external view returns (bool) {
return providers[providerAddress].isVerified;
}
function issuePrescription(
string calldata patientID,
string calldata drug,
uint dosage,
uint duration
) external onlyRole(DOCTOR_ROLE) {
prescriptions[patientID].push(Prescription({
doctor: msg.sender,
drug: drug,
dosage: dosage,
duration: duration,
timestamp: block.timestamp
}));
emit PrescriptionIssued(msg.sender, patientID, drug, dosage, duration);
}
function getPrescriptions(string calldata patientID) external view returns (Prescription[] memory) {
return prescriptions[patientID];
}
}
I searched online and found that increasing the gas limit would help my case but no such thing happened. Additionally, I tried optimizing the code by replacing the lists I had made for registered providers and verified providers with events. Can anyone please tell me if my code is optimized or not?
Upvotes: 0
Views: 112