1.0.114 • Published 6 months ago

smartnftportal v1.0.114

Weekly downloads
-
License
BSD-3-Clause-Attr...
Repository
github
Last release
6 months ago

<SmartNFTPortal>

A <SmartNFTPortal> is a React control which renders Smart NFTs in the browser. This widget takes care of the <iframe> sandbox, and provides the Smart NFT Javascript API to any NFT which is rendered inside it. This provides a great deal of extra power to Javascript NFTs, enabling them to respond to changes on the blockchain, as well as load additional assets such as Javascript libraries, images, and other data directly from the blockchain.

While this API provides a lot of additional functionality to NFTs inside the sandbox, it's important to note that they are still fully sandboxed - this control handles all the necessary inter-process communication between the sandboxed iframe and its parent document using the sendMessage() API.

The first Smart NFT collection

Click here to see it in action in the Smart NFT Playground.

The source code of the Smart NFT Playground is also available.

libcip54 provides the backend queries necessary to support this API on Cardano.

Click here to read the Cardano Improvement Proposal

This control, and the API in general is intended to be applicable to any UTXO blockchain - in particular if there's interest it may be ported to Bitcoin BRC20, and Ergo native tokens too. Currently, libcip54 provides the backend functionality for Cardano, but it would be a simple matter to port this library to other blockchains (the queries will just need to be tweaked for different chain indexers)

Installing

$ npm install smartnftportal
or
$ yarn add smartnftportal

Exports

The default export is <SmartNFTPortal>. To use it:

import { SmartNFTPortal } from "smartnftportal"

React Smart NFT Portal Usage

At minimum you must pass in the NFT metadata, and the smartImports structure, which has been generated by libcip54. Libcip54 is a node.js library which provides the backend queries to import this data from the Cardano blockchain via the DBSync chain indexer - so if you have your own DBSync server, this is the preferred option. If you don't have a DBSync server, then you can query the Plutus.art API for the same data.

import React from 'react'
import { SmartNFTPortal } from 'smartnftportal'
import axios from "axios"

function App() {
  const [nft,setNft] = React.useState(null);
  React.useEffect(()=> { 
    axios.get('https://plutus-art-dev.herokuapp.com/asset/1eaf3b3ffb75ff27c43c512c23c6450b307f138281efb1d690b8465231').then((d)=>{
        setNft(d.data);
    });
  },[]);
  return (
    <div className="App">
      <header className="App-header">
        <div style={{ width: 400 }}>
          <SmartNFTPortal 
            smartImports={nft?.smartImports}
            metadata={nft?.metadata}
            loading={!nft}
             />
        </div>
      </header>
    </div>
  )
}

export default App

<SmartNFTPortal />

The following properties are available on the control:

loading: boolean

When true, the control will assume the metadata and smartImports fields haven't been populated yet and will display a loading message

smartImports: object

This is a complex object containing all the imports from the blockchain - intended to be generated by libcip54

metadata: object

This is a copy of the NFT's metadata - if it's a CIP68 asset, the metadata should be converted from the CBOR into a JSON format that matches CIP25 assets.

loadingContent: object

default: <div>Loading...</div>

A react control or JSX tag to display when the control is loading

apiRoot: string

default: null

The initial smartImport object should contain all the data needed to initially render the NFT, but some NFTs may choose to request additional data as they run - the necessary endpoints are provided in libcip54.

className: string

default:

Provide a custom class name for the iframe tag itself.

focus: boolean

default: false

If true, the iframe will attempt to request focus() after the initial document has loaded.

onFocus: function

default null

A callback function for the focus event

onBlur: function

default null

A callback function for the blur event

style: object

default: null

CSS Styles

random: number

default: null

Just a quick way to trigger a refresh of the component

inactiveHtmlStyle: string

default: ''

A snippet of CSS to add to the <html> tag within the sandbox when is not focused

activeHtmlStyle: string

default: ''

A snippet of CSS to add to the <html> tag within the sandbox when is focused

onReady: function

default null

A callback function for when the iframe's dom is ready

onScroll: function

default null

A callback function to get the scroll event from within the iframe

onMouseOver: function

default null

A callback function for the mouseover event

onMouseOut: function

default null

A callback function for the mouseout event

onClick: function

default null

A callback function for the click event

onMouseDown: function

default null

A callback function for the mousedown event

onMouseUp: function

default null

A callback function for the mouseup event

onMouseMove: function

default null

A callback function for the mousemove event

onContextMenu: function

default null

A callback function for the contextmenu event

onDblClick: function

default null

A callback function for the dblClick event

onTouchStart: function

default null

A callback function for the touchstart event

onTouchEnd: function

default null

A callback function for the touchend event

onTouchMove: function

default null

A callback function for the touchmove event

onTouchCancel: function

default null

A callback function for the touchcancel event

1.0.107

6 months ago

1.0.106

6 months ago

1.0.109

6 months ago

1.0.108

6 months ago

1.0.105

6 months ago

1.0.110

6 months ago

1.0.112

6 months ago

1.0.111

6 months ago

1.0.114

6 months ago

1.0.113

6 months ago

1.0.104

9 months ago

1.0.103

9 months ago

1.0.102

9 months ago

1.0.101

9 months ago

1.0.100

9 months ago

1.0.99

9 months ago

1.0.98

9 months ago

1.0.97

9 months ago

1.0.96

9 months ago

1.0.95

9 months ago

1.0.94

9 months ago

1.0.93

9 months ago

1.0.92

9 months ago

1.0.91

9 months ago

1.0.90

9 months ago

1.0.89

9 months ago

1.0.88

9 months ago

1.0.87

9 months ago

1.0.86

10 months ago

1.0.85

10 months ago

1.0.84

10 months ago

1.0.83

11 months ago

1.0.82

11 months ago

1.0.81

11 months ago

1.0.80

11 months ago

1.0.79

11 months ago

1.0.78

11 months ago

1.0.77

11 months ago

1.0.76

11 months ago

1.0.74

11 months ago

1.0.73

11 months ago

1.0.72

11 months ago

1.0.71

11 months ago

1.0.70

11 months ago

1.0.69

11 months ago

1.0.68

11 months ago

1.0.67

11 months ago

1.0.66

11 months ago

1.0.65

11 months ago

1.0.64

11 months ago

1.0.63

11 months ago

1.0.62

11 months ago

1.0.61

11 months ago

1.0.60

11 months ago

1.0.59

11 months ago

1.0.58

11 months ago

1.0.57

11 months ago

1.0.56

11 months ago

1.0.55

11 months ago

1.0.54

11 months ago

1.0.53

11 months ago

1.0.52

11 months ago

1.0.51

11 months ago

1.0.50

11 months ago

1.0.49

11 months ago

1.0.48

11 months ago

1.0.47

11 months ago

1.0.46

11 months ago

1.0.45

11 months ago

1.0.44

11 months ago

1.0.43

11 months ago

1.0.42

11 months ago

1.0.41

11 months ago

1.0.40

11 months ago

1.0.39

11 months ago

1.0.38

11 months ago

1.0.37

11 months ago

1.0.36

11 months ago

1.0.35

11 months ago

1.0.34

11 months ago

1.0.33

11 months ago

1.0.32

11 months ago

1.0.31

11 months ago

1.0.30

11 months ago

1.0.29

11 months ago

1.0.28

11 months ago

1.0.27

11 months ago

1.0.26

11 months ago

1.0.25

11 months ago

1.0.24

11 months ago

1.0.23

11 months ago

1.0.22

11 months ago

1.0.21

11 months ago

1.0.20

11 months ago

1.0.19

11 months ago

1.0.18

11 months ago

1.0.17

11 months ago

1.0.16

11 months ago

1.0.15

11 months ago

1.0.14

11 months ago

1.0.13

11 months ago

1.0.12

11 months ago

1.0.11

11 months ago

1.0.10

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago