Token Negotiator
  • Introduction
  • Quick Start
    • Getting Started with NFT's
    • Getting Started with Fungible Tokens
    • Getting Started with Off Chain Tokens
  • Learn
    • Installation
    • Supported Chains
    • Supported Wallets
    • Supported Attestations
    • Event Hooks
    • Issuer Configurations
      • Issuer Configuration EVM
      • Issuer Configuration Solana
      • Issuer Configuration Flow
      • Issuer Configuration Ultra
      • Issuer Configuration Socios
      • Issuer Configuration Off Chain
    • Active Negotiation (UI)
      • Custom Views
      • View Navigation
      • Theme
      • Configuration Options
    • Passive Negotiation (no UI)
      • Wallet Connection
    • Token Authentication
      • Off Chain Authentication
      • On Chain Token Authentication (evm)
    • Smart Contract and wallet Interaction
      • Sign message
    • Off Chain Token Issuers
  • Reference
  • Articles
  • Videos
  • Showcase
  • Contribution
  • Support
  • Migrating from version 2x to 3x
  • Github Examples
Powered by GitBook
On this page
  1. Learn

Smart Contract and wallet Interaction

Interaction with Smart Contracts and wallet features

PreviousOn Chain Token Authentication (evm)NextSign message

Last updated 1 year ago

Interaction with Smart Contracts and wallet technology features can be done via Token Negotiator.

For EVM smart contract integration an instance of Ethers.js can be access via:

window._ethers
// or
_ethers

Resources:

Example usage:

In the scenario below the Token Negotiator provides these functionalities to a website once a users wallet is connected:

  • To learn if a user holds tokens of specific collection(s) to offer them gated perks

  • To allow users to mint new tokens of a specific collection(s)

The details needed to make this on chain interaction are:

  • Smart Contract Address

  • Application Binary Interface (ABI)

  • Connected Wallet address to send the token to

  • Token URI (e.g. )

Example Usage:

const negotiator = new Client({
        type: "active",
        issuers: [{
		blockchain: "evm",
		onChain: true,
		collectionID: "expansion-punks-collection",
		contract: "0x0d0167a823c6619d430b1a96ad85b888bcf97c37",
		chain: "eth",
        }],
        uiOptions: {
          openingHeading:
            "Gain discounts and experiences with your expansion punk nft.",
          issuerHeading: "Get discounts with tokens",
          repeatAction: "try again",
          position: "bottom-right"
	}
});
	
negotiator.negotiate();

let currentConnectedWallet = null

negotiator.on("connected-wallet", (connectedWallet) => {
    currentConnectedWallet = connectedWallet;
});

const safeMint = (contract, abi, sendTo, tokenUri) => {

	negotiator.ui.showLoaderDelayed([
		"<h4>Let's Mint an NFT...</h4>",
		"<small>Please sign the new transaction in your wallet</small>"
	], 200, true);
	
	try {
	
		const contract = new _ethers.Contract(contract, abi, currentConnectedWallet.provider.getSigner());
	
		const tx = await contract.safeMint(sendTo, tokenUri);
		
		negotiator.ui.showLoaderDelayed([ 
			"<h4>Minting your NFT</h4>",
			"<small>Transaction in progress...</small>"
		], 0, true);
	
		await tx.wait();
	
		negotiator.ui.dismissLoader()
		
		return {
			status: `Your transaction was successful: ${chain} ${tx?.hash}`
		}
	
	} catch (error) {
	
		negotiator.ui.showError('This transaction failed, please try again.');
	
		return {
			error: true,
			status: `This transaction failed. Please try again. ${error}`
		}
	
	}

}

For support and any questions please reach out to us on or via sayhi@smarttokenlabs.com

https://docs.ethers.org/v5
https://ipfs.io/ipfs/bafybeih7roxjr3jjaxvmrjpwja5mkx3kn4w5icvxtntbwbyw5l6stlgcbq/16461
discord