EasyConnect

Overview

EasyConnect is a small wrapper around PhantasmaLink from phantasma-sdk-ts. It manages login and exposes helpers for signing transactions.

circle-info

For the layer map and quick choice, see Wallet Connection.

When to use

  • Frontend apps that want a smaller API than PhantasmaLink.

  • Carbon signing via signCarbonTransaction.

  • Non-React projects (for React, see @phantasma/connect-react).

Install

npm install phantasma-sdk-ts

Configuration

EasyConnect supports three configuration styles:

  • new EasyConnect() uses:

    • requiredVersion = 4

    • platform = "phantasma"

    • providerHint = "poltergeist"

    • and then calls setConfig("auto")

  • new EasyConnect([version, platform, providerHint]) overrides the defaults.

  • setConfig("auto" | "poltergeist" | "ecto") sets the provider hint.

setConfig("auto") checks window.PhantasmaLinkSocket. If it exists, it switches to ecto; otherwise it leaves providerHint empty.

circle-info

EasyConnect is intended for browser use. The default config reads from window.

Connect (async wrapper)

EasyConnect.connect uses callbacks. If you prefer async/await, wrap it:

Account info

After a successful connection, conn.link.account contains:

  • alias

  • name

  • address

  • avatar

  • platform

  • external

  • balances

  • files

Signing helpers

EasyConnect exposes the following helpers:

  • signTransaction(script, payload, onSuccess, onFail) (VM transactions)

  • signCarbonTransaction(txMsg, onSuccess, onFail) (Carbon transactions)

  • signData(data, onSuccess, onFail)

  • invokeScript(script, callback)

  • disconnect()

signCarbonTransaction calls PhantasmaLink.signCarbonTxAndBroadcast, which requires Phantasma Link protocol v4 or higher.

EasyConnect exposes the underlying PhantasmaLink instance as conn.link. If you want a custom dApp ID, set it before connecting:

Last updated