-
Notifications
You must be signed in to change notification settings - Fork 644
/
main.go
79 lines (70 loc) · 2.07 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
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package main
import (
"context"
"log"
"time"
"github.com/ava-labs/avalanchego/genesis"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/formatting/address"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/platformvm/stakeable"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/ava-labs/avalanchego/wallet/subnet/primary"
)
func main() {
key := genesis.EWOQKey
uri := primary.LocalAPIURI
kc := secp256k1fx.NewKeychain(key)
amount := 500 * units.MilliAvax
locktime := uint64(time.Date(2030, 1, 1, 0, 0, 0, 0, time.UTC).Unix())
destAddrStr := "P-local18jma8ppw3nhx5r4ap8clazz0dps7rv5u00z96u"
destAddr, err := address.ParseToID(destAddrStr)
if err != nil {
log.Fatalf("failed to parse address: %s\n", err)
}
ctx := context.Background()
// MakeWallet fetches the available UTXOs owned by [kc] on the network that
// [uri] is hosting.
walletSyncStartTime := time.Now()
wallet, err := primary.MakeWallet(ctx, &primary.WalletConfig{
URI: uri,
AVAXKeychain: kc,
EthKeychain: kc,
})
if err != nil {
log.Fatalf("failed to initialize wallet: %s\n", err)
}
log.Printf("synced wallet in %s\n", time.Since(walletSyncStartTime))
// Get the P-chain wallet
pWallet := wallet.P()
pBuilder := pWallet.Builder()
pContext := pBuilder.Context()
avaxAssetID := pContext.AVAXAssetID
issueTxStartTime := time.Now()
tx, err := pWallet.IssueBaseTx([]*avax.TransferableOutput{
{
Asset: avax.Asset{
ID: avaxAssetID,
},
Out: &stakeable.LockOut{
Locktime: locktime,
TransferableOut: &secp256k1fx.TransferOutput{
Amt: amount,
OutputOwners: secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{
destAddr,
},
},
},
},
},
})
if err != nil {
log.Fatalf("failed to issue transaction: %s\n", err)
}
log.Printf("issued %s in %s\n", tx.ID(), time.Since(issueTxStartTime))
}