Browse Source

transfer

master
Lev 2 years ago
parent
commit
b7ce982abc
  1. 26
      build/cli.js
  2. 16
      contracts/main.ts

26
build/cli.js

@ -1,8 +1,9 @@
const main = require('../contracts/main');
const subcommand = require('subcommand');
const {Address, SendMode, InternalMessage, CommonMessageInfo, StateInit, CellMessage} = require("ton");
const {Address, SendMode, InternalMessage, CommonMessageInfo, StateInit, CellMessage, Cell} = require("ton");
const {getWallet} = require("../contracts/main");
const {sendInternalMessageWithWallet} = require("../contracts/utils");
const {hex} = require("../build/jetton-wallet.compiled.json")
const argv = process.argv.slice(2);
@ -44,6 +45,29 @@ let commands = [
body: main.withdrawMsg((parseFloat(args._[1]) * main.TON()))
})
}
},
{
name: 'transfer',
options: [
{
name: 'minter',
help: 'The jetton address'
},
{
name: "amount"
},
{
name: "target"
}
],
command: async function transfer(args) {
let [walletContract, walletKey] = await getWallet();
let address = main.getJettonAddress(walletContract.address, Address.parse(args._[0]), Cell.fromBoc(hex)[0]);
await sendInternalMessageWithWallet({
walletContract, secretKey: walletKey.secretKey, value: 0.15 * main.TON(), to: address,
body: main.transferMsg((parseFloat(args._[1]) * main.TON()), Address.parse(args._[2]))
})
}
}
]

16
contracts/main.ts

@ -67,6 +67,22 @@ export function walletData(params: { balance: number, ownerAddress: Address, jet
.endCell();
}
export function getJettonAddress(ownerAddress: Address, jettonMasterAddress: Address, jettonWalletCode: Cell): Address {
return contractAddress({
workchain: 0,
initialData: walletData({balance: 0, ownerAddress, jettonMasterAddress, jettonWalletCode}),
initialCode: jettonWalletCode
});
}
export function transferMsg(amount: number, recipient: Address) {
return beginCell()
.storeUint(0xf8a7ea5, 32)
.storeUint(0, 64)
.storeCoins(amount)
.storeAddress(recipient)
.endCell();
}
export function TON(): number {
return 1000000000;

Loading…
Cancel
Save