-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
69 lines (52 loc) · 2.2 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* import dotenv from "dotenv";
dotenv.config({ path: "/.env" }); */
import {Address, TonClient} from "ton";
import {unixNow} from '../contracts/contracts/lib/utils';
import {MineMessageParams, Queries} from "../contracts/contracts/giver/NftGiver.data";
import {BN} from 'bn.js';
async function main () {
// everything test net for now, .env config would be created later
const wallet = Address.parse(
"kQCkB8cE4Yf1Y8HRkR-BcrMgj6ysce-YOnz6bIuNn0dZrLRN"
); //owner address
const collection = Address.parse(
"EQDMyD57dbDgxbu7PQqJJuJCxoeU-advQpBjOgM48YY3vxxO"
); //where do we add them
const client = new TonClient({
endpoint: "https://testnet.toncenter.com/api/v2/jsonRPC",
apiKey: "7af1a809e91c0df4d3969230e3a50dc58907637d069d8ca358838cc69dfeddde",
});
const miningData = await client.runMethod(collection, 'get_mining_data');
const parseStackNum = (sn: any) => new BN(sn[1].substring(2), 'hex');
const complexity = parseStackNum(miningData.stack[0]);
const mineParams : MineMessageParams = {
expire: unixNow() + 300, // 5 min is enough to make a transaction
mintTo: wallet, // your wallet
data1: new BN(0), // temp variable to increment in the miner
seed:new BN(0) // unique seed from get_mining_data - how to initialize
};
let msg = Queries.mine(mineParams); // transaction builder
while (new BN(msg.hash(), 'be').gt(complexity)) {
mineParams.expire = unixNow() + 300
mineParams.data1.iaddn(1)
msg = Queries.mine(mineParams)
}
let progress = 0;
while (new BN(msg.hash(), 'be').gt(complexity)) {
progress += 1
console.clear()
console.log(`Mining started: please, wait for 30-60 seconds to mine your NFT!`)
console.log(' ')
console.log(`⛏ Mined ${progress} hashes! Last: `, new BN(msg.hash(), 'be').toString())
mineParams.expire = unixNow() + 300
mineParams.data1.iaddn(1)
msg = Queries.mine(mineParams)
}
console.log(' ')
console.log('💎 Mission completed: msg_hash less than pow_complexity found!');
console.log(' ')
console.log('msg_hash: ', new BN(msg.hash(), 'be').toString())
console.log('pow_complexity: ', complexity.toString())
console.log('msg_hash < pow_complexity: ', new BN(msg.hash(), 'be').lt(complexity))
}
main()