1

The newest Transparent Proxy from Openzeppelin deploys the admin contract by itself and emits an event from where we can find the admin contract's address.

This event is emitted during the deployment transaction, along with 3 other events. Here is an example of the transaction

How should I fetch and parse that event from the transaction receipt to get the admin address, just after deployment?

1 Answer 1

0

Following code will do your work

const { ethers } = require("ethers");
const ABI = <Contract ABI>
const rpcProvider = new ethers.JsonRpcProvider(
  <rpc url>
);

async function getEventFromReceipt(provider, abi, tx, topic) {
  const receipt = await provider.getTransactionReceipt(tx);
  const iface = new ethers.Interface(abi);
  const logs = receipt.logs.filter((log) => log.topics[0] === topic);
  const log = logs.map((log) => iface.parseLog(log));
  return log[0].args[1];
}

getEventFromReceipt(
  rpcProvider,
  ABI,
  "0xc85faee1096a44612402871bea6cbba77dc7c9c8471409286334c7cc746a1889",
  "0x7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f"
).then((newAdmin) => {
  console.log("New Admin", newAdmin);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.