Deploy
Compile the contract
const fs = require("fs").promises;
const solc = require("solc");
async function main() {
// Load the contract source code
const sourceCode = await fs.readFile("SimpleStorage.sol", "utf8");
// Compile the source code and retrieve the ABI and bytecode
const { abi, bytecode } = compile(sourceCode, "SimpleStorage");
// Store the ABI and bytecode into a JSON file
const artifact = JSON.stringify({ abi, bytecode }, null, 2);
await fs.writeFile("SimpleStorage.json", artifact);
}
function compile(sourceCode, contractName) {
// Create the Solidity Compiler Standard Input and Output JSON
const input = {
language: "Solidity",
sources: { main: { content: sourceCode } },
settings: { outputSelection: { "*": { "*": ["abi", "evm.bytecode"] } } },
};
// Parse the compiler output to retrieve the ABI and bytecode
const output = solc.compile(JSON.stringify(input));
const artifact = JSON.parse(output).contracts.main[contractName];
return {
abi: artifact.abi,
bytecode: artifact.evm.bytecode.object,
};
}
main().then(() => process.exit(0));Deployment examples
1. Using eth_sendTransaction
eth_sendTransaction2. Using web3.eth.Contract
web3.eth.Contract3. Using eth_sendSignedTransaction
eth_sendSignedTransactionLast updated
Was this helpful?

