|
1 | | -import { assertEx } from '@xylabs/assert' |
2 | 1 | import { isError } from '@xylabs/typeof' |
3 | 2 | import { PayloadBuilder } from '@xyo-network/payload-builder' |
4 | 3 | import type { Payload } from '@xyo-network/payload-model' |
5 | 4 | import type { HashPayload, SignedHydratedTransaction } from '@xyo-network/xl1-protocol' |
6 | | -import { |
7 | | - ADDRESS_INDEX, generateXyoBaseWalletFromPhrase, |
8 | | - SimpleXyoGatewayRunner, |
9 | | - SimpleXyoSigner, |
10 | | -} from '@xyo-network/xl1-protocol-sdk' |
11 | | -import { HttpRpcXyoConnection } from '@xyo-network/xl1-rpc' |
12 | 5 | import { config } from 'dotenv' |
13 | 6 |
|
| 7 | +import { getGateway } from './getGateway.ts' |
| 8 | + |
14 | 9 | // Load environment variables from .env file |
15 | 10 | config({ quiet: true }) |
16 | 11 |
|
17 | 12 | const logger = console |
18 | 13 |
|
19 | | -export async function helloWorld(mnemonic?: string, rpcEndpoint = 'http://localhost:8080/rpc'): Promise<void> { |
| 14 | +export async function helloWorld(mnemonic?: string): Promise<void> { |
20 | 15 | try { |
21 | 16 | console.log('\n**** Starting XL1 Hello World NodeJs Sample ****\n') |
22 | 17 |
|
23 | | - // Load the account to use for the transaction |
24 | | - const walletMnemonic = assertEx(process.env.XYO_WALLET_MNEMONIC ?? mnemonic, () => 'Unable to resolve mnemonic from environment variable or argument') |
25 | | - const account = await (await generateXyoBaseWalletFromPhrase(walletMnemonic)).derivePath(ADDRESS_INDEX.XYO) |
26 | | - console.log('Using account:', account.address) |
27 | | - |
28 | | - // Determine the RPC endpoint to use for the chain connection |
29 | | - const endpoint = process.env.XYO_CHAIN_RPC_URL ?? rpcEndpoint |
30 | | - console.log('Using endpoint:', endpoint) |
31 | | - |
32 | | - // Create a new RPC connection |
33 | | - const connection = new HttpRpcXyoConnection({ endpoint }) |
34 | | - const signer = new SimpleXyoSigner(account) |
35 | | - const gateway = new SimpleXyoGatewayRunner(connection, signer) |
36 | | - |
37 | 18 | // Generate random data to send in the transaction |
38 | 19 | const { onChainData, offChainData } = await getRandomTransactionData() |
39 | 20 |
|
| 21 | + const gateway = await getGateway(mnemonic) |
| 22 | + |
40 | 23 | // Send the transaction to the network |
41 | 24 | const [txHash] = await gateway.addPayloadsToChain(onChainData, offChainData) |
42 | 25 |
|
|
0 commit comments