Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publish contract to object instead of account #120

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 123 additions & 94 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions templates/digital-asset-template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"version": "0.0.0",
"license": "Apache-2.0",
"scripts": {
"move:init": "node ./scripts/init && node ./scripts/update_env",
"move:init": "node ./scripts/init",
"move:test": "node ./scripts/move/test",
"move:compile": "node ./scripts/move/compile",
"move:publish": "node ./scripts/move/publish",
"move:upgrade": "node ./scripts/move/upgrade",
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
Expand All @@ -16,7 +17,7 @@
"fmt": "npm run _fmt -- --write"
},
"dependencies": {
"@aptos-labs/ts-sdk": "1.20.0",
"@aptos-labs/ts-sdk": "1.22.1",
"@aptos-labs/wallet-adapter-react": "^3.3.0",
"@irys/sdk": "^0.2.1",
"@radix-ui/react-accordion": "^1.1.2",
Expand Down
63 changes: 43 additions & 20 deletions templates/digital-asset-template/scripts/move/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,55 @@ const yaml = require("js-yaml");
const cli = require("@aptos-labs/ts-sdk/dist/common/cli/index.js");

const config = yaml.load(fs.readFileSync("./.aptos/config.yaml", "utf8"));
const accountAddress =
config["profiles"][process.env.PROJECT_NAME]["account"];
const accountAddress = config["profiles"][process.env.PROJECT_NAME]["account"];

async function publish() {
if (!process.env.VITE_COLLECTION_CREATOR_ADDRESS) {
throw new Error(
"VITE_COLLECTION_CREATOR_ADDRESS variable is not set, make sure you set it on the .env file"
);
throw new Error("VITE_COLLECTION_CREATOR_ADDRESS variable is not set, make sure you set it on the .env file");
}

const move = new cli.Move();

await move.publish({
packageDirectoryPath: "move",
namedAddresses: {
// Publish module to account address
launchpad_addr: accountAddress,
// This is the address you want to use to create collection with, e.g. an address in Petra so you can create collection in UI using Petra
initial_creator_addr: process.env.VITE_COLLECTION_CREATOR_ADDRESS,
// Our contract depends on the token-minter contract to provide some common functionalities like managing refs and mint stages
// You can read the source code of it here: https://github.com/aptos-labs/token-minter/
// Please find it on the network you are using, This is testnet deployment
minter:
"0x3c41ff6b5845e0094e19888cba63773591be9de59cafa9e582386f6af15dd490",
},
profile: `${process.env.PROJECT_NAME}-${process.env.VITE_APP_NETWORK}`,
});
move
.createObjectAndPublishPackage({
packageDirectoryPath: "move",
addressName: "launchpad_addr",
namedAddresses: {
// Publish module to new object, but since we create the object on the fly, we fill in the publisher's account address here
launchpad_addr: accountAddress,
// This is the address you want to use to create collection with, e.g. an address in Petra so you can create collection in UI using Petra
initial_creator_addr: process.env.VITE_COLLECTION_CREATOR_ADDRESS,
// Our contract depends on the token-minter contract to provide some common functionalities like managing refs and mint stages
// You can read the source code of it here: https://github.com/aptos-labs/token-minter/
// Please find it on the network you are using, This is testnet deployment
minter: "0x3c41ff6b5845e0094e19888cba63773591be9de59cafa9e582386f6af15dd490",
},
profile: `${process.env.PROJECT_NAME}-${process.env.VITE_APP_NETWORK}`,
})
.then((objectAddress) => {
const filePath = ".env";
let envContent = "";

// Check .env file exists and read it
if (fs.existsSync(filePath)) {
envContent = fs.readFileSync(filePath, "utf8");
}

// Regular expression to match the VITE_MODULE_ADDRESS variable
const regex = /^VITE_MODULE_ADDRESS=.*$/m;
const newEntry = `VITE_MODULE_ADDRESS=${objectAddress}`;

// Check if VITE_MODULE_ADDRESS is already defined
if (envContent.match(regex)) {
// If the variable exists, replace it with the new value
envContent = envContent.replace(regex, newEntry);
} else {
// If the variable does not exist, append it
envContent += `\n${newEntry}`;
}

// Write the updated content back to the .env file
fs.writeFileSync(filePath, envContent, "utf8");
});
}
publish();
Loading
Loading