Giter Club home page Giter Club logo

cardano-mint-site's Introduction

Nami Wallet examples

PartyAnimalsCardanoFanBoyMinter

We implemented many Nami wallet functionalities for our NFT project "Party Animals" https://partyanimals.dance and https://cfanboyminter.web.app/.

In this repository, we want to share how to implement the basic functionalities of Nami Wallet on your website.

About Nami Wallet

Nami Wallet is a browser-based wallet extension to interact with the Cardano blockchain. It's an open-source project and built by Berry Pool.

You can download the wallet for different browsers here (https://namiwallet.io)

If you find this repository useful and want to support us, you can donate ADA to this wallet addr1qysjrwqv6uyu7gtwtzvhjceauj8axmrhssqf3cvxangadqzt5f4xjh3za5jug5rw9uykv2klc5c66uzahu65vajvfscshgt2vq.

Setup

To run the application locally these installation steps:

// Install packages for application
npm install

// Install the module with cardano serialization lib
cd src/nami-js
npm install

// Return to workspace
cd ../..

To run the application start the node process with

npm run start

Run our example app to try out the functionalities of our package.

Before you can use the NamiWalletApi you have to create an account to get a blockfrost api key https://blockfrost.io/. Create a ./config.js file and add your API key information.

const blockfrostApiKey = {
    0: "rbkrp5hOr3khPAWNo3x47t6CP7qKFyA5", // testnet
    1: "mainnetfqH0CVlBesnsj5IKhgIYCn231KzqUOyk" // mainnet
}

export default blockfrostApiKey;

Getting started

Import Nami Wallet

import NamiWalletApi, { Cardano } from './nami-js';

//React example
let nami; 
 useEffect(() => {
        async function t() {

            const S = await Cardano();
            nami = new NamiWalletApi(
                S,
                window.cardano,
               {
                0: "yourBlockfrostTestnetApiKey", // testnet
                1: "yourBlockfrostMainnetApiKey" // mainnet
                }   
            )
        }
        t()
    }, [])

Before you can use the NamiWalletApi you have to create an account to get a blockfrost api key https://blockfrost.io/.

Check if Nami is installed

nami.isInstalled()

Check if Nami is enabled

nami.isEnabled() 

Enable Nami

nami.enable()

Get Bech32 Address

let address = nami.getAddress() 
console.log(address)

Nami Address Hex Format

nami.getHexAddress()

Get Current Network of Nami

let network = nami.getNetworkId()
console.log(network)

Get balance and assets in wallet (be aware that the amount can be more than shown in the nami wallet because if you hold NFTs those capture some of your ADA)

async nami.getBalance () : {lovelave: <amountLovelace>, assets: <assetList>}

Build transaction

let transaction = await nami.transaction( PaymentAddress = "", 
recipients = [{address: "", amount: "0" ,assets:[],   mintedAssets: []}], 
metadata = null, 
metadataHash = null, 
addMetadata = true, 
utxosRaw = [],
networkId = 0, 
ttl = 3600, 
multiSig = false) 


// Example 

let transaction = await nami.transaction(
    PaymentAddress = "addr_test1qqe5eg44cq6805apc2wru7vk0tdn6weurckl9j0jwx958af8yp00jmh469gvx9vlyf6fwf9dfkjselmyvylm8yjyufuskfku3a", 
    utxos = (await nami.getUtxosHex()), 
    recipients = [{address:"addr_test1qqsjrwqv6uyu7gtwtzvhjceauj8axmrhssqf3cvxangadqzt5f4xjh3za5jug5rw9uykv2klc5c66uzahu65vajvfscs57k2ql","amount":"3",
    assets: [{unit:"5612bdcde30b1edf25823f62aa73c1b06831fb0f406c6c812da455db.TestNft", quantity: "1"}],  // Existing Assets
    mintedAssets:[{"assetName":"MyNFT","quantity":"1",
    "policyId":"Example PolicyID","policyScript":"ExamplePolicy"}] // NFTs to be minted
    ], // list of recipients
    metadata = {"721":
    {"8201828200581c334ca2b5c03477d3a1c29c3e79967adb3d3b3c1e2df2c9f2718b43f582051a030c5adf":
    {"MyNFT":{"name":"MyNFT","description":"This is a test NFT","image":"ipfs://QmUb8fW7qm1zCLhiKLcFH9yTCZ3hpsuKdkTgKmC8iFhxV8"}}}} //Metadata following NFT standard

Sign transaction

const witness = await nami.signTx(transaction)

Submit transaction with blockfrost API

await nami.submitTx( transactionRaw,witnesses,scripts,networkId)

//Example 
let txHash = await nami.submitTx( {transactionRaw: transaction,
                witnesses: [witness],
                networkId : (await getNetworkId()).id))
console.log(txHash)

Create Minitng Policy

await nami.createLockingPolicyScript(address,  (await getNetworkId()).id , expirationTime)

// example policy that expires in 90 minutes from now
const expirationTime = new Date();
expirationTime.setTime(expirationTime.getTime() + (1 * 60 * 90 * 1000))

let policy = await nami.createLockingPolicyScript(await nami.getHexAddress(), networkId , expirationTime)

Hash Metadata (needed for multi-signature minting)

nami.hashMetadata(metadata)

Vending NFTs with multi-signature approach

If you want to sell your NFTs with a multi-signature approach, have a look here Multi-Signature.md

Feature Requests

If you want to see any additional functionalities you can leave a feature request. We are going to expand this repository over time and react to your feedback.

Support

If you find this repository helpful, please follow me on twitter https://twitter.com/CardanoFanB and have a look at our projects NFT Project https://partyanimals.dance and https://cfanboyminter.web.app/. If you like you can donate ADA to this wallet addr1qysjrwqv6uyu7gtwtzvhjceauj8axmrhssqf3cvxangadqzt5f4xjh3za5jug5rw9uykv2klc5c66uzahu65vajvfscshgt2vq. Thank you for you support!

cardano-mint-site's People

Contributors

prideofguardian0607 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.