Smart Contract and wallet Interaction
Interaction with Smart Contracts and wallet features
window._ethers
// or
_ethersLast updated
Interaction with Smart Contracts and wallet features
window._ethers
// or
_ethersLast updated
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}`
}
}
}