Signing the transaction
Signing the transaction requires some values that can be obtained as explained in previous steps, such as avoNonce
, domain name
and version
etc.
const types = {
Cast: [
{ name: "params", type: "CastParams" },
{ name: "forwardParams", type: "CastForwardParams" },
],
CastParams: [
{ name: "actions", type: "Action[]" },
{ name: "id", type: "uint256" },
{ name: "avoNonce", type: "int256" },
{ name: "salt", type: "bytes32" },
{ name: "source", type: "address" },
{ name: "metadata", type: "bytes" },
],
Action: [
{ name: "target", type: "address" },
{ name: "data", type: "bytes" },
{ name: "value", type: "uint256" },
{ name: "operation", type: "uint256" },
],
CastForwardParams: [
{ name: "gas", type: "uint256" },
{ name: "gasPrice", type: "uint256" },
{ name: "validAfter", type: "uint256" },
{ name: "validUntil", type: "uint256" },
{ name: "value", type: "uint256" },
],
};
const avocadoRPCChainId = "634";
const chainId = (await polygonProvider.getNetwork()).chainId; // e.g. when executing later on Polygon
const domain = {
name: domainName, // see previous steps
version: domainVersion, // see previous steps
chainId: avocadoRPCChainId,
verifyingContract: avocadoAddress, // see previous steps
salt: ethers.utils.solidityKeccak256(["uint256"], [chainId]), // salt is set to actual chain id where execution happens
};
// make sure you are on chain id 634 (to interact with Avocado RPC)
const avoSigner = provider.getSigner();
// sign transaction payload as built in previous step
const signature = await avoSigner._signTypedData(domain, types, txPayload);