storage-node.ts 920 B

123456789101112131415161718192021222324252627282930313233
  1. import { config } from 'dotenv'
  2. import { WsProvider } from '@polkadot/api'
  3. import { ApolloClient, InMemoryCache } from '@apollo/client'
  4. import { QueryNodeApi } from '../Api'
  5. import getContentFromStorageNode from '../flows/storageNode/getContentFromStorageNode'
  6. const scenario = async () => {
  7. // Load env variables
  8. config()
  9. const env = process.env
  10. const queryNodeProvider = new ApolloClient({
  11. uri: env.QUERY_NODE_URL,
  12. cache: new InMemoryCache(),
  13. defaultOptions: { query: { fetchPolicy: 'no-cache', errorPolicy: 'all' } },
  14. })
  15. const api: QueryNodeApi = await QueryNodeApi.new(
  16. new WsProvider(env.NODE_URL),
  17. queryNodeProvider,
  18. env.TREASURY_ACCOUNT_URI || '//Alice',
  19. env.SUDO_ACCOUNT_URI || '//Alice'
  20. )
  21. await getContentFromStorageNode(api)
  22. // Note: disconnecting and then reconnecting to the chain in the same process
  23. // doesn't seem to work!
  24. api.close()
  25. }
  26. scenario()