Browse Source

tranfer stuff

master
Lev 2 years ago
parent
commit
386d268053
  1. 33
      build/cli.js
  2. 4
      contracts/main.ts
  3. 13
      contracts/utils.ts

33
build/cli.js

@ -50,8 +50,8 @@ let commands = [
name: 'transfer', name: 'transfer',
options: [ options: [
{ {
name: 'minter', name: 'my_wallet',
help: 'The jetton address' help: 'The jetton wallet address'
}, },
{ {
name: "amount" name: "amount"
@ -62,12 +62,37 @@ let commands = [
], ],
command: async function transfer(args) { command: async function transfer(args) {
let [walletContract, walletKey] = await getWallet(); let [walletContract, walletKey] = await getWallet();
let address = main.getJettonAddress(walletContract.address, Address.parse(args._[0]), Cell.fromBoc(hex)[0]);
await sendInternalMessageWithWallet({ await sendInternalMessageWithWallet({
walletContract, secretKey: walletKey.secretKey, value: 0.15 * main.TON(), to: address, walletContract, secretKey: walletKey.secretKey, value: 0.15 * main.TON(), to: Address.parse(args._[0]),
body: main.transferMsg((parseFloat(args._[1]) * main.TON()), Address.parse(args._[2])) body: main.transferMsg((parseFloat(args._[1]) * main.TON()), Address.parse(args._[2]))
}) })
} }
},
{
name: "deploy",
options: [
{
name: "minter",
},
{
name: "account"
}
],
command: async function deploy(args) {
let [walletContract, walletKey] = await getWallet();
let address = main.getJettonAddress(Address.parse(args._[1]), Address.parse(args._[0]), Cell.fromBoc(hex)[0]);
await sendInternalMessageWithWallet({
walletContract, secretKey: walletKey.secretKey, value: 0.15 * main.TON(), to: address,
body: new CommonMessageInfo({
body: null,
stateInit: new StateInit({ code: Cell.fromBoc(hex)[0], data: main.walletData({
balance: 0, ownerAddress: Address.parse(args._[1]),
jettonWalletCode: Cell.fromBoc(hex)[0],
jettonMasterAddress: Address.parse(args._[0])
}) }),
})
})
}
} }
] ]

4
contracts/main.ts

@ -81,6 +81,10 @@ export function transferMsg(amount: number, recipient: Address) {
.storeUint(0, 64) .storeUint(0, 64)
.storeCoins(amount) .storeCoins(amount)
.storeAddress(recipient) .storeAddress(recipient)
.storeAddress(recipient)
.storeBit(false)
.storeCoins(0)
.storeBit(false)
.endCell(); .endCell();
} }

13
contracts/utils.ts

@ -2,8 +2,13 @@ import { Address, Cell, CellMessage, InternalMessage, CommonMessageInfo, WalletC
import BN from "bn.js"; import BN from "bn.js";
// helper for end-to-end on-chain tests (normally post deploy) to allow sending InternalMessages to contracts using a wallet // helper for end-to-end on-chain tests (normally post deploy) to allow sending InternalMessages to contracts using a wallet
export async function sendInternalMessageWithWallet(params: { walletContract: WalletContract; secretKey: Buffer; to: Address; value: BN; bounce?: boolean; body?: Cell }) { export async function sendInternalMessageWithWallet(params: { walletContract: WalletContract; secretKey: Buffer; to: Address; value: BN; bounce?: boolean; body?: Cell | CommonMessageInfo }) {
const message = params.body ? new CellMessage(params.body) : undefined; if (params.body instanceof Cell) {
params.body = new CommonMessageInfo({ body: new CellMessage(params.body) });
}
if (!params.body) {
params.body = new CommonMessageInfo({});
}
const seqno = await params.walletContract.getSeqNo(); const seqno = await params.walletContract.getSeqNo();
const transfer = params.walletContract.createTransfer({ const transfer = params.walletContract.createTransfer({
secretKey: params.secretKey, secretKey: params.secretKey,
@ -13,9 +18,7 @@ export async function sendInternalMessageWithWallet(params: { walletContract: Wa
to: params.to, to: params.to,
value: params.value, value: params.value,
bounce: params.bounce ?? false, bounce: params.bounce ?? false,
body: new CommonMessageInfo({ body: params.body,
body: message,
}),
}), }),
}); });
await params.walletContract.client.sendExternalMessage(params.walletContract, transfer); await params.walletContract.client.sendExternalMessage(params.walletContract, transfer);

Loading…
Cancel
Save