I used solc compiler in react app but browser is not compatible with it and gives an error after using that code;
const createContract = async () => {
const contract = erc1155.print();
console.log(contract);
compileSmartContract(contract);
};
function compileSmartContract(sourceCode: string): CompilationOutput {
const input = {
language: "Solidity",
sources: {
"MyContract.sol": {
content: sourceCode,
},
},
settings: {
outputSelection: {
"*": {
"*": ["abi", "evm.bytecode"],
},
},
},
};
const output = JSON.parse(solc.compile(JSON.stringify(input)));
if (!output.contracts["MyContract.sol"]) {
throw new Error("Compilation failed");
}
const contract = output.contracts["MyContract.sol"].MyContract;
const abi = JSON.stringify(contract.abi);
const bytecode = contract.evm.bytecode.object;
return { abi, bytecode };
}
Also I tried remix API and truffle compilers to compile smart contract and get bytecode and abi of it. Is there any proper way to compile given contract ?