-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce57100
commit e17cde5
Showing
4 changed files
with
91 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package examples | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/ava-labs/avalanche-tooling-sdk-go/constants" | ||
"github.com/ava-labs/avalanche-tooling-sdk-go/keychain" | ||
"github.com/ava-labs/avalanche-tooling-sdk-go/validator" | ||
"github.com/ava-labs/avalanche-tooling-sdk-go/wallet" | ||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/utils/units" | ||
"github.com/ava-labs/avalanchego/vms/secp256k1fx" | ||
"github.com/ava-labs/avalanchego/wallet/subnet/primary" | ||
"time" | ||
|
||
"github.com/ava-labs/avalanche-tooling-sdk-go/avalanche" | ||
"github.com/ava-labs/avalanche-tooling-sdk-go/node" | ||
) | ||
|
||
func ValidatePrimaryNetwork() { | ||
node := node.Node{ | ||
// NodeID is Avalanche Node ID of the node | ||
NodeID: "NODE_ID", | ||
// IP address of the node | ||
IP: "NODE_IP_ADDRESS", | ||
// SSH configuration for the node | ||
SSHConfig: node.SSHConfig{ | ||
User: constants.RemoteHostUser, | ||
PrivateKeyPath: "NODE_KEYPAIR_PRIVATE_KEY_PATH", | ||
}, | ||
// Role of the node can be Validator, API, AWMRelayer, Loadtest, or Monitor | ||
Roles: []node.SupportedRole{node.Validator}, | ||
} | ||
|
||
nodeID, err := ids.NodeIDFromString(node.NodeID) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
validatorParams := validator.PrimaryNetworkValidatorParams{ | ||
NodeID: nodeID, | ||
// Validate Primary Network for 48 hours | ||
Duration: 48 * time.Hour, | ||
// Stake 2 AVAX | ||
StakeAmount: 2 * units.Avax, | ||
} | ||
|
||
// Key that will be used for paying the transaction fee of AddValidator Tx | ||
network := avalanche.FujiNetwork() | ||
keychain, err := keychain.NewKeychain(network, "PRIVATE_KEY_FILEPATH", nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
wallet, err := wallet.New( | ||
context.Background(), | ||
&primary.WalletConfig{ | ||
URI: network.Endpoint, | ||
AVAXKeychain: keychain.Keychain, | ||
EthKeychain: secp256k1fx.NewKeychain(), | ||
PChainTxsToFetch: nil, | ||
}, | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
txID, err := node.ValidatePrimaryNetwork(avalanche.FujiNetwork(), validatorParams, wallet) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Printf("obtained tx id %s", txID.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters