Socket
Socket
Sign inDemoInstall

sui-svelte

Package Overview
Dependencies
96
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    sui-svelte

[![npm version](https://badge.fury.io/js/sui-svelte.svg)](https://badge.fury.io/js/sui-svelte)


Version published
Maintainers
1
Created

Readme

Source

Sui Svelte

npm version

Provides components for interacting with Sui wallets.

Showcase

SuiForge uses sui-svelte to interact with SUI wallets.

Setup

Barebones example:

routes/+page.svelte

<script lang="ts">
    import {ConnectButton} from "sui-svelte/ConnectButton"
    import {SuiModule, account, SuiModule} from "sui-svelte/SuiModule"
    
    // (Optional) Callback to call when a Sui account is connected
    const onConnect = () => {
        if (account.value) {
        console.log("Connected address: ", account.value.address)
        }
    }
</script>

<SuiModule {onConnect} />
<ConnectButton />
{#if account.value}
    <div>Connected address: {account.value.address}</div>
{/if}

Getting connected account

The account object exposes the connected account.

<script lang="ts">
   import { account } from "sui-svelte/SuiModule"

   console.log("Is account connected?", account.value !== undefined)
   if (account.value) {
       console.log("Connected account object:", account.value)
       console.log("Connected address:", account.value.address)
   }
</script>

Sending transactions

Refer to Sui guide on building transactions.

<script lang="ts">
   import { signAndExecuteTransactionBlock } from "sui-svelte/SuiModule"
   import { TransactionBlock } from "@mysten/sui.js/transactions"

   const sendTx = () => {
       const txb = new TransactionBlock()
       // Create a new coin with balance 100, based on the coins used as gas payment
       const [coin] = txb.splitCoins(txb.gas, [txb.pure(100)])
       // Transfer the split coin to a specific address
       txb.transferObjects([coin], txb.pure("0xSomeSuiAddress"))

       // Execute using sui-svelte
       signAndExecuteTransactionBlock(txb)
   }
</script>

Manually trigger connect modal

<script lang="ts">
   import { connectWithModal } from "sui-svelte/SuiModule"

   connectWithModal()
</script>

Customization

ConnectButton

Is a <button> componnet and can be customized by passing a class or styles prop.

<ConnectButton class="my-button-class" style="background: red;" />

ConnectModal

The modal for connecting can be customized by passing a "modal" slot to the SuiModule.

You should always open the modal using the ConnectButton or the connect exported method from SuiModule, since this starts the process that ends when resolve gets called.

<script lang="ts">
    import {SuiModule} from "sui-svelte/SuiModule"
    import {connectModal, resolve} from "sui-svelte/ConnectModal"
    import type { IWallet } from "@suiet/wallet-sdk"

    // Get the wallet from the browser
    func getWallet = (): IWallet  => {
        ...
        return suietWallet
    }

    // Call the modal resolve function with the wallet
    const selectWallet = () => {
        const wallet = getWallet()
        resolve.value(wallet)
    }

    // If closed, call the close method of connectModal
    const onClose = () => {
        connectModal.close()
    }
</script>

<SuiModule>
    <div slot="modal">
        <button onclick={onClose}> Close </button>
        <button onclick={selectWallet}> Select wallet </button>
    </div>
</SuiModule>

Issues and contributions

Feel free to submit PRs, or issues for any doubts or feature requests.

Contact

contact@encypherstudio.com

Keywords

FAQs

Last updated on 24 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc