-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathmain.go
79 lines (62 loc) · 2.72 KB
/
main.go
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
70
71
72
73
74
75
76
77
78
79
package main
import (
"context"
"encoding/base64"
"github.com/xssnick/tonutils-go/address"
"github.com/xssnick/tonutils-go/liteclient"
"github.com/xssnick/tonutils-go/tlb"
"github.com/xssnick/tonutils-go/ton"
"github.com/xssnick/tonutils-go/ton/wallet"
"log"
"strings"
)
func main() {
// for completely offline mode you could use liteclient.NewOfflineClient() instead
client := liteclient.NewConnectionPool()
// connect to mainnet lite server
err := client.AddConnection(context.Background(), "135.181.140.212:13206", "K0t3+IWLOXHYMvMcrGZDPs+pn58a17LFbnXoQkKc2xw=")
if err != nil {
log.Fatalln("connection err: ", err.Error())
return
}
api := ton.NewAPIClient(client)
// bound all requests to single ton node
ctx := client.StickyContext(context.Background())
// seed words of account, you can generate them with any wallet or using wallet.NewSeed() method
words := strings.Split("birth pattern then forest walnut then phrase walnut fan pumpkin pattern then cluster blossom verify then forest velvet pond fiction pattern collect then then", " ")
w, err := wallet.FromSeed(api, words, wallet.V3)
if err != nil {
log.Fatalln("FromSeed err:", err.Error())
return
}
log.Println("wallet address:", w.WalletAddress())
addr := address.MustParseAddr("EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N")
log.Println("sending transaction...")
// default message ttl is 3 minutes, it is time during which you can send it to blockchain
// if you need to set longer TTL, you could use this method
// w.GetSpec().(*wallet.SpecV3).SetMessagesTTL(uint32((10 * time.Minute) / time.Second))
w.GetSpec().(*wallet.SpecV3).SetSeqnoFetcher(func(ctx context.Context, sub uint32) (uint32, error) {
// Get seqno from your database here, this func will be called during BuildTransfer to get seqno for transaction
return 1, nil
})
comment, _ := wallet.CreateCommentCell("Hello from tonutils-go!")
withStateInit := true // if wallet is initialized, you may set false to not send additional data
// if destination wallet is not initialized you should set bounce = true
ext, err := w.PrepareExternalMessageForMany(context.Background(), withStateInit, []*wallet.Message{
wallet.SimpleMessageAutoBounce(addr, tlb.MustFromTON("0.003"), comment),
})
if err != nil {
log.Fatalln("BuildTransfer err:", err.Error())
return
}
// if you wish to send message from diff source, or later, you could serialize it to BoC
msgCell, _ := tlb.ToCell(ext)
log.Println(base64.StdEncoding.EncodeToString(msgCell.ToBOC()))
// send message to blockchain
if err = api.SendExternalMessage(ctx, ext); err != nil {
log.Fatalln("Failed to send external message:", err.Error())
return
}
log.Println("transaction sent, we are not waiting for confirmation")
return
}