polygon cdk变更TrustedSequencerURL
背景
特殊场景需要变更合约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);
});