Smart Contract and wallet Interaction

Interaction with Smart Contracts and wallet features

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:

https://docs.ethers.org/v5

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:

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 discord or via sayhi@smarttokenlabs.com

Last updated