Read Avocado values

Note: Make sure to read the Understand section first.

Examples here prerequisite the setup steps.

Get avocado address by owner and index

const avocadoAddress = await forwarder.computeAvocado(
  ownerAddress, // owner EOA address
  index // index 0 is treated as avocado personal on https://avocado.instadapp.io/
);

Check if Avocado is deployed on a specific network

const isDeployed = (await polygonProvider.getCode(avocadoAddress)) !== "0x";

Get Avocado domain name and version on a specific network

let domainName, domainVersion; // domain separator name & version required for building signatures

if (isDeployed) {
  // if avocado is deployed, can read values directly from there
  const avocado = new ethers.Contract(avocadoAddress, avocadoV1ABI, polygonProvider);

  [domainName, domainVersion] = await Promise.all([avocado.DOMAIN_SEPARATOR_NAME(), avocado.DOMAIN_SEPARATOR_VERSION()]);
} else {
  // if avocado is not deployed yet, AvoForwarder will resolve to the default values set when deploying the Avocado
  [domainName, domainVersion] = await Promise.all([forwarder.avocadoVersionName(ownerAddress, index), forwarder.avocadoVersion(ownerAddress, index)]);
}

Get sequential nonce, signers, requiredSigners, owner

const avocado = new ethers.Contract(avocadoAddress, avocadoV1ABI, polygonProvider);

const nonce = isDeployed ? await avocado.avoNonce() : 0;
const signers = isDeployed ? await avocado.signers() : [ownerAddress];
const requiredSigners = isDeployed ? await avocado.requiredSigners() : 1;
const owner = isDeployed ? await avocado.owner() : "probably the signer?";