快速开始
在 5 分钟内将你的第一个 Solidity 合约部署到 Rome。
最后更新于
这有帮助吗?
这有帮助吗?
mkdir rome-hello && cd rome-hello
npx hardhat --init 中添加 Rome 网络:
martius: {
type: "http",
chainType: "l1",
chainId: 121214,
url: "https://martius.testnet.romeprotocol.xyz/",
accounts: [configVariable("PRIVATE_KEY")],
},
rome_local: {
type: "http",
chainType: "l1",
chainId: 1001,
url: "http://localhost:9090",
accounts: [configVariable("PRIVATE_KEY")],
},
},export PRIVATE_KEY="0xYOUR_PRIVATE_KEY"// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
contract HelloRome {
string public greeting = "来自 Solana 的问候!";
uint256 public counter;
event Greeted(address indexed sender, uint256 count);
function greet() external returns (string memory) {
counter++;
emit Greeted(msg.sender, counter);
return greeting;
}
function setGreeting(string calldata _greeting) external {
greeting = _greeting;
}
}import hardhat from "hardhat";
async function main() {
const { viem } = await hardhat.network.connect();
const publicClient = await viem.getPublicClient();
const hello = await viem.deployContract("HelloRome");
console.log("HelloRome 已部署到:", hello.address);
const hash = await hello.write.greet();
await publicClient.waitForTransactionReceipt({ hash });
console.log("计数器:", (await hello.read.counter()).toString());
console.log("问候语:", await hello.read.greeting());
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});npx hardhat run scripts/deploy.ts --network martiusHelloRome 已部署到: 0x09c437e305eeb698e1776cff23ca16c1bb25aabd
计数器:1
问候语:来自 Solana 的问候!