@nomad-xyz/sdk
    TypeScript icon, indicating that this package has built-in type declarations

    2.1.0-rc.0 • Public • Published

    Nomad SDK

    This package includes the NomadContext, a management system for Nomad core contracts, which inherits from the MultiProvider. NomadContext allows developers to easily interact with the Nomad system on any number of networks.


    Documentation


    Setup (front-end only)

    Configure webpack with wasm, syncWebAssembly and topLevelAwait:

    module: {
      rules: [
        {
          test: /\.wasm$/,
          type: 'webassembly/sync',
        },
      ],
    },
    experiments: {
      syncWebAssembly: true,
      topLevelAwait: true,
    },

    Intended Usage

    Instantiate a NomadContext:

    // sdk includes a wasm module, so must await the import
    const { NomadContext } = await import('@nomad-xyz/sdk')
    
    type Env = 'production' | 'staging' | 'development'
    // staging is the recommended testnet environment
    const environment: Env = 'staging'
    // instantiate a preconfigured NomadContext
    const nomadContext = await NomadContext.fetch(environment)

    Commonly used methods:

    // register custom rpc provider
    nomadContext.registerRpcProvider('ethereum', 'https://...')
    // register signer
    nomadContext.registerSigner('ethereum', someSigner)
    
    // convert domain name to domain ID
    nomadContext.resolveDomain('ethereum') // nomad domain ID: 6648936
    // convert domain ID to domain name
    nomadContext.resolveDomainName(6648936) // nomad domain name: ethereum
    
    // get the core nomad contracts for a given domain
    nomadContext.getCore('ethereum')
    // get the replica contract for ethereum on moonbeam
    nomadContext.mustGetReplicaFor('moonbeam', 'ethereum')
    
    // check liveness
    nomadContext.checkHomes(['ethereum', 'moonbeam'])
    nomadContext.blacklist() // returns set of down networks, if any

    Fetch a NomadMessage

    import { NomadMessage } from '@nomad-xyz/sdk'
    const message = await NomadMessage.baseSingleFromTransactionHash(nomadContext, 'ethereum', '0x1234...')
    // get the status of a message (NOT RECOMMENDED FOR USAGE IN PRODUCTION)
    // 1 = dispatched
    // 2 = included
    // 3 = relayed
    // 4 = processed
    const { status } = await message.events()
    // get a timestamp (in seconds) when a message will be ready to process
    // on the destination
    const confirmAt = await message.confirmAt()
    // manually claim on destination after latency period
    // Ethereum destination only
    const receipt = await message.process()

    Building

    yarn build
    

    Keywords

    Install

    npm i @nomad-xyz/sdk

    DownloadsWeekly Downloads

    318

    Version

    2.1.0-rc.0

    License

    Apache-2.0 OR MIT

    Unpacked Size

    145 kB

    Total Files

    48

    Last publish

    Collaborators

    • annascarroll
    • ltchang
    • yourbuddyconner
    • prestwich
    • imti
    • erinhales