We wanted to simplify the contract versioning wit the objective of avoiding having the same contract with different names in the repo StargateNFTV1, StargateNFTV2...
At the same time we want to ensure starage integrity between upgrades so we need the previous versions of the contracts to be able to test that the storage does not get corrupted between versions.
The approach to avoid having different copies of the same contract at the same time we can access the previous contracts for testing purposes was to publish the artifacts and types generated by the contracts compilation into a separate npm package that can be used later on.
This package lives under the packages/contracts-artifacts folder, and is a simple npm project that copies the artifactsand the typescript-types generated by the compilation of the contrads and compiles them into ESMomdules and CommonJS for the different consumers that may be interested in using this package.
yarn install @vechain/stargate-contracts-artifacts
# or
npm install @vechain/stargate-contracts-artifactsThis will install the lates version of the package but you can install specific versions of this pagacke by appending @{version} to the name of the package.
This will add an entry in your package.json. Since the idea is that you may want to have this package installed multiple times, one for each version. You my need to change your package.json from this:
{
"@vechain/stargate-contracts-artifacts": "1.0.0",
"@vechain/stargate-contracts-artifacts": "2.0.0",
"@vechain/stargate-contracts-artifacts": "3.0.0"
}to this
{
"@vechain/stargate-contracts-artifacts-1-0-0": "npm:@vechain/stargate-contracts-artifacts@1.0.0",
"@vechain/stargate-contracts-artifacts-2-0-0": "npm:@vechain/stargate-contracts-artifacts@2.0.0",
"@vechain/stargate-contracts-artifacts-3-0-0": "npm:@vechain/stargate-contracts-artifacts@3.0.0"
}This way all the version can be accesed from the same project.
The contracts name will not change between releases so in case you are importing the same contract multiple times you are going to need to rename the import.
import { StargateNFT__factory } from "../typechain-types";
import { StargateNFT__factory as StargateNFTV1_0_0__factory } from "@vechain/stargate-contracts-artifacts-1-0-0";
import { StargateNFT__factory as StargateNFTV2_0_0__factory } from "@vechain/stargate-contracts-artifacts-2-0-0";
import { StargateNFT__factory as StargateNFTV3_0_0__factory } from "@vechain/stargate-contracts-artifacts-3-0-0";The release of new versions of the npm package can only be done from the public repository for stargate. To achieve you will need to first merge a PR with the updated version in the package.json under packages/contracts-artifacts/package.json
{
"version": "{new_version}"
}After that you will only need to create a github release with exactly the same version you used in the package.json file and the github action will trigger and release new version on npm.
-
I have updated the version in the
package.jsonfile under thepackages/contracts-artifactsfolder. -
I have written a meaningful description of all the changes introduced, including versions of the contracts
-
I have created a release with the exact same version used previously in the
package.json