Browse Source

Improved deploy script

master
Tal Kol 2 years ago
parent
commit
63b418c00c
  1. 9
      README.md
  2. 17
      build/deploy.ts

9
README.md

@ -75,7 +75,10 @@ To setup your machine for development, please make sure you have the following:
* Tests are running inside Node.js by running TVM in web-assembly using `ton-contract-executor` * Tests are running inside Node.js by running TVM in web-assembly using `ton-contract-executor`
* Deploy * Deploy
* In the root repo dir, run in terminal `npm run deploy` * Make sure all contracts are built and your setup is ready to deploy:
* Follow the on-screen instructions to deploy to mainnet
* Each contract to deploy should have a script `build/mycontract.deploy.ts` to return its init data cell * Each contract to deploy should have a script `build/mycontract.deploy.ts` to return its init data cell
* The deployment wallet is configured in `build/deploy.config.json` (file will be created if not found) * The deployment wallet is configured in `build/deploy.config.json` (it will be created if not found)
* To deploy to mainnet (production), run in terminal `npm run deploy`
* To deploy to testnet instead (where TON is free), run `npm run deploy:testnet`
* Follow the on-screen instructions of the deploy script

17
build/deploy.ts

@ -48,11 +48,13 @@ async function main() {
const client = new TonClient({ endpoint: `https://${process.env.TESTNET ? "testnet." : ""}toncenter.com/api/v2/jsonRPC` }); const client = new TonClient({ endpoint: `https://${process.env.TESTNET ? "testnet." : ""}toncenter.com/api/v2/jsonRPC` });
const walletKey = await mnemonicToWalletKey(deployerMnemonic.split(" ")); const walletKey = await mnemonicToWalletKey(deployerMnemonic.split(" "));
const walletContract = WalletContract.create(client, WalletV3R2Source.create({ publicKey: walletKey.publicKey, workchain: 0 })); const walletContract = WalletContract.create(client, WalletV3R2Source.create({ publicKey: walletKey.publicKey, workchain: 0 }));
console.log(` - Wallet address used for deployment is: ${walletContract.address.toFriendly()}`); console.log(` - Wallet address used to deploy from is: ${walletContract.address.toFriendly()}`);
const walletBalance = await client.getBalance(walletContract.address); const walletBalance = await client.getBalance(walletContract.address);
if (walletBalance.lt(toNano(1))) { if (walletBalance.lt(toNano(0.2))) {
console.log(` - ERROR: Wallet has less than 1 TON for gas (${fromNano(walletBalance)} TON), please send some TON for gas first`); console.log(` - ERROR: Wallet has less than 0.2 TON for gas (${fromNano(walletBalance)} TON), please send some TON for gas first`);
process.exit(1); process.exit(1);
} else {
console.log(` - Wallet balance is ${fromNano(walletBalance)} TON, which will be used for gas`);
} }
// go over all the contracts we have deploy scripts for // go over all the contracts we have deploy scripts for
@ -102,7 +104,7 @@ async function main() {
sendMode: SendMode.PAY_GAS_SEPARATLY + SendMode.IGNORE_ERRORS, sendMode: SendMode.PAY_GAS_SEPARATLY + SendMode.IGNORE_ERRORS,
order: new InternalMessage({ order: new InternalMessage({
to: newContractAddress, to: newContractAddress,
value: toNano(0.1), value: toNano(0.02), // this will almost in full be the balance of the new contract and allow it to pay rent
bounce: false, bounce: false,
body: new CommonMessageInfo({ body: new CommonMessageInfo({
stateInit: new StateInit({ data: initDataCell, code: initCodeCell }), stateInit: new StateInit({ data: initDataCell, code: initCodeCell }),
@ -114,13 +116,16 @@ async function main() {
console.log(` - Deploy transaction sent successfully`); console.log(` - Deploy transaction sent successfully`);
// make sure that the contract was deployed // make sure that the contract was deployed
console.log(` - Waiting 5 seconds to check if the contract was actually deployed..`); console.log(` - Waiting 10 seconds to check if the contract was actually deployed..`);
await sleep(5000); await sleep(10000);
if (await client.isContractDeployed(newContractAddress)) { if (await client.isContractDeployed(newContractAddress)) {
console.log(` - SUCCESS! Contract deployed successfully to address: ${newContractAddress.toFriendly()}`); console.log(` - SUCCESS! Contract deployed successfully to address: ${newContractAddress.toFriendly()}`);
const contractBalance = await client.getBalance(newContractAddress);
console.log(` - New contract balance is now ${fromNano(contractBalance)} TON, make sure it has enough to pay rent`);
} else { } else {
console.log(` - FAILURE! Contract address still looks uninitialized: ${newContractAddress.toFriendly()}`); console.log(` - FAILURE! Contract address still looks uninitialized: ${newContractAddress.toFriendly()}`);
} }
console.log(` - Block explorer link: https://${process.env.TESTNET ? "test." : ""}tonwhales.com/explorer/address/${newContractAddress.toFriendly()}`);
} }
console.log(``); console.log(``);

Loading…
Cancel
Save