init
This commit is contained in:
42
scripts/deployGift.ts
Normal file
42
scripts/deployGift.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { toNano, Address } from '@ton/core';
|
||||
import { Gift } from '../build/Gift/Gift_Gift';
|
||||
import { NetworkProvider } from '@ton/blueprint';
|
||||
import { mnemonicToPrivateKey } from '@ton/crypto';
|
||||
import { WalletContractV4 } from '@ton/ton';
|
||||
import { encryptMessage, getRecipientPublicKey } from './crypto/crypto';
|
||||
|
||||
export async function run(provider: NetworkProvider) {
|
||||
const ui = provider.ui();
|
||||
|
||||
let wallet = provider.sender();
|
||||
let kp = await mnemonicToPrivateKey(process.env.WALLET_MNEMONIC!!.split(' '));
|
||||
let walletContract = provider.open(
|
||||
WalletContractV4.create({
|
||||
workchain: provider.sender().address!!.workChain,
|
||||
publicKey: kp.publicKey,
|
||||
}),
|
||||
);
|
||||
|
||||
let receiverAddress = await ui.inputAddress('Receiver address');
|
||||
let text = await ui.input('Text content');
|
||||
let imageUrlString = null; // await ui.input('ImageUrl (optional)');
|
||||
|
||||
let content = { $$type: 'Content' as const, content: text, imageUrl: imageUrlString || null };
|
||||
let recipientPublicKey = await getRecipientPublicKey(receiverAddress);
|
||||
let encrypted = await encryptMessage(content, kp.secretKey, recipientPublicKey);
|
||||
let encryptedContent = {
|
||||
$$type: 'Content' as const,
|
||||
content: Buffer.from(encrypted).toString('base64'),
|
||||
imageUrl: null,
|
||||
};
|
||||
|
||||
const gift = provider.open(await Gift.fromInit(encryptedContent, receiverAddress));
|
||||
|
||||
await wallet.send({
|
||||
to: gift.address,
|
||||
value: toNano('0.05'),
|
||||
init: gift.init,
|
||||
});
|
||||
|
||||
await provider.waitForDeploy(gift.address);
|
||||
}
|
||||
Reference in New Issue
Block a user