|
|
|
@ -6,17 +6,19 @@
|
|
|
|
|
|
|
|
|
|
import axios from "axios"; |
|
|
|
|
import axiosThrottle from "axios-request-throttle"; |
|
|
|
|
axiosThrottle.use(axios, { requestsPerSecond: 0.5 }); // required since toncenter jsonRPC limits to 1 req/sec without API key
|
|
|
|
|
|
|
|
|
|
axiosThrottle.use(axios, {requestsPerSecond: 0.5}); // required since toncenter jsonRPC limits to 1 req/sec without API key
|
|
|
|
|
|
|
|
|
|
import dotenv from "dotenv"; |
|
|
|
|
|
|
|
|
|
dotenv.config(); |
|
|
|
|
|
|
|
|
|
import fs from "fs"; |
|
|
|
|
import path from "path"; |
|
|
|
|
import glob from "fast-glob"; |
|
|
|
|
import { Address, Cell, CellMessage, CommonMessageInfo, fromNano, InternalMessage, StateInit, toNano } from "ton"; |
|
|
|
|
import { TonClient, WalletContract, WalletV3R2Source, contractAddress, SendMode } from "ton"; |
|
|
|
|
import { mnemonicNew, mnemonicToWalletKey } from "ton-crypto"; |
|
|
|
|
import {Address, Cell, CellMessage, CommonMessageInfo, fromNano, InternalMessage, StateInit, toNano} from "ton"; |
|
|
|
|
import {TonClient, WalletContract, WalletV3R2Source, contractAddress, SendMode} from "ton"; |
|
|
|
|
import {mnemonicNew, mnemonicToWalletKey} from "ton-crypto"; |
|
|
|
|
|
|
|
|
|
async function main() { |
|
|
|
|
console.log(`=================================================================`); |
|
|
|
@ -32,7 +34,10 @@ async function main() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// initialize globals
|
|
|
|
|
const client = new TonClient({ endpoint: `https://${isTestnet ? "testnet." : ""}toncenter.com/api/v2/jsonRPC` }); |
|
|
|
|
const client = new TonClient({ |
|
|
|
|
endpoint: `https://${isTestnet ? "testnet." : ""}toncenter.com/api/v2/jsonRPC`, |
|
|
|
|
apiKey: isTestnet ? 'bed2b4589201ff3c575be653593f912a337c08eed416b60b02345763b9ee9c36' : 'a1e8a1055a387515158589dc7e9bad3035e7db2b9f9ea5cdad6b727f71e328db' |
|
|
|
|
}); |
|
|
|
|
const deployerWalletType = "org.ton.wallets.v3.r2"; // also see WalletV3R2Source class used below
|
|
|
|
|
const newContractFunding = toNano(0.02); // this will be (almost in full) the balance of a new deployed contract and allow it to pay rent
|
|
|
|
|
const workchain = 0; // normally 0, only special contracts should be deployed to masterchain (-1)
|
|
|
|
@ -53,7 +58,10 @@ async function main() {
|
|
|
|
|
|
|
|
|
|
// open the wallet and make sure it has enough TON
|
|
|
|
|
const walletKey = await mnemonicToWalletKey(deployerMnemonic.split(" ")); |
|
|
|
|
const walletContract = WalletContract.create(client, WalletV3R2Source.create({ publicKey: walletKey.publicKey, workchain })); |
|
|
|
|
const walletContract = WalletContract.create(client, WalletV3R2Source.create({ |
|
|
|
|
publicKey: walletKey.publicKey, |
|
|
|
|
workchain |
|
|
|
|
})); |
|
|
|
|
console.log(` - Wallet address used to deploy from is: ${walletContract.address.toFriendly()}`); |
|
|
|
|
const walletBalance = await client.getBalance(walletContract.address); |
|
|
|
|
if (walletBalance.lt(toNano(0.2))) { |
|
|
|
@ -97,7 +105,7 @@ async function main() {
|
|
|
|
|
const initCodeCell = Cell.fromBoc(JSON.parse(fs.readFileSync(hexArtifact).toString()).hex)[0]; |
|
|
|
|
|
|
|
|
|
// make sure the contract was not already deployed
|
|
|
|
|
const newContractAddress = contractAddress({ workchain, initialData: initDataCell, initialCode: initCodeCell }); |
|
|
|
|
const newContractAddress = contractAddress({workchain, initialData: initDataCell, initialCode: initCodeCell}); |
|
|
|
|
console.log(` - Based on your init code+data, your new contract address is: ${newContractAddress.toFriendly()}`); |
|
|
|
|
if (await client.isContractDeployed(newContractAddress)) { |
|
|
|
|
console.log(` - Looks like the contract is already deployed in this address, skipping deployment`); |
|
|
|
@ -117,7 +125,7 @@ async function main() {
|
|
|
|
|
value: newContractFunding, |
|
|
|
|
bounce: false, |
|
|
|
|
body: new CommonMessageInfo({ |
|
|
|
|
stateInit: new StateInit({ data: initDataCell, code: initCodeCell }), |
|
|
|
|
stateInit: new StateInit({data: initDataCell, code: initCodeCell}), |
|
|
|
|
body: initMessageCell !== null ? new CellMessage(initMessageCell) : null, |
|
|
|
|
}), |
|
|
|
|
}), |
|
|
|
|