-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxion-connect.js
More file actions
64 lines (56 loc) · 1.97 KB
/
Copy pathxion-connect.js
File metadata and controls
64 lines (56 loc) · 1.97 KB
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
// xion-connect.js
const { StargateClient, SigningStargateClient, GasPrice } = require("@cosmjs/stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { CosmWasmClient, SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const config = require('./config');
// Validate configuration before proceeding
config.validateConfig();
/**
* Creates a read-only client for querying the blockchain
* This client can be used for all operations that don't require signing
*/
async function getQueryClient() {
return await StargateClient.connect(config.XION_RPC_URL);
}
/**
* Creates a CosmWasm client for querying and executing smart contracts
*/
async function getCosmWasmClient() {
return await CosmWasmClient.connect(config.XION_RPC_URL);
}
/**
* Creates a signing client that can perform transactions
* By default uses the mnemonic from environment variables
* Can optionally accept a different mnemonic for multi-wallet scenarios
*/
async function getSigningClient(mnemonic = config.MNEMONIC) {
// Create wallet from mnemonic
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
prefix: "xion" // XION address prefix
});
// Create and return a signing client
return await SigningStargateClient.connectWithSigner(
config.XION_RPC_URL,
wallet,
{ gasPrice: GasPrice.fromString("0.025uxion") }
);
}
async function getSigningCosmWasmClient(mnemonic = config.MNEMONIC) {
// Create wallet from mnemonic
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
prefix: "xion" // XION address prefix
});
// Create and return a signing client
return await SigningCosmWasmClient.connectWithSigner(
config.XION_RPC_URL,
wallet,
{ gasPrice: GasPrice.fromString("0.025uxion") }
);
}
module.exports = {
getQueryClient,
getSigningClient,
getSigningCosmWasmClient,
getCosmWasmClient,
CHAIN_ID: config.CHAIN_ID
};