背景
特殊场景需要变更合约PolygonZkEVM.sol中的TrustedSequencerURL
合约代码
/**
* @notice Allow the admin to set the trusted sequencer URL
* @param newTrustedSequencerURL URL of trusted sequencer
*/
function setTrustedSequencerURL(
string memory newTrustedSequencerURL
) external onlyAdmin {
trustedSequencerURL = newTrustedSequencerURL;
emit SetTrustedSequencerURL(newTrustedSequencerURL);
}
ABI
[{
"inputs": [
{
"internalType": "string",
"name": "newTrustedSequencerURL",
"type": "string"
}
],
"name": "setTrustedSequencerURL",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}]
测试
当前合约内TrustedSequencerURL:http://172.18.36.173:8123
期望变更为:http://172.18.39.162:8123
直接使用在线工具:https://www.smartcontractgui.xyz/
PolygonZkEVM合约地址在create_rollup_output.json->rollupAddress: 0x584eF34da0d700082d3c29cD3844d9524e656950
import { ethers } from 'hardhat';
import path from 'path';
import fs from 'fs';
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
import createRollupParameters from './create_rollup_output.json';
async function main() {
const privateKey = path.join(__dirname, 'keystore', './admin.privateKey');
const data = fs.readFileSync(privateKey, 'UTF-8');
const wa = new ethers.Wallet(data, ethers.provider);
console.log(`Use ${wa.address}`);
const polygonZkEVM = (await ethers.getContractFactory('PolygonZkEVM', wa)).attach(createRollupParameters.rollupAddress);
console.log(await polygonZkEVM.trustedSequencerURL());
const tx = await polygonZkEVM.setTrustedSequencerURL("http://172.18.39.162:8123");
await tx.wait(1);
console.log(await polygonZkEVM.trustedSequencerURL());
}
main().catch((error) => {
console.error(error);
process.exit(1);
});
版权属于:区块链中文技术社区 / 转载原创者
本文链接:https://bcskill.com/index.php/archives/1987.html
相关技术文章仅限于相关区块链底层技术研究,禁止用于非法用途,后果自负!本站严格遵守一切相关法律政策!