Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions contract/Integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const Web3 = Noderequire('web3');
const PaymentNFTContract = Noderequire('<path-to-contract-abi>');
const contractAddress = '<address-of-contract>';
const web3 = new Web3('<rpc-endpoint>');

// Instantiate the contract object
const paymentNFTContract = new web3.eth.Contract(PaymentNFTContract.abi, contractAddress);

// Add event listener for payment confirmation
document.getElementById('payment-button').addEventListener('click', async () => {
const paymentAmount = // Get payment amount from user input
const accounts = await web3.eth.getAccounts();
await paymentNFTContract.methods.pay().send({from: accounts[0], value: paymentAmount});
// Notify the user that payment was successful
});

// Add event listener for NFT purchase
document.getElementById('nft-purchase-button').addEventListener('click', async () => {
const accounts = await web3.eth.getAccounts();
await paymentNFTContract.methods.purchaseNFT().send({from: accounts[0]});
// Notify the user that the NFT was purchased and transferred to their wallet
});

/*
The payment-button and nft-purchase-button elements are assumed to be present in the HTML page, and event listeners are added to handle payment and NFT purchase actions.

When the payment button is clicked, the pay() function is called on the contract with the payment amount and sender's account address. Once the transaction is confirmed, the user is notified that the payment was successful.

When the NFT purchase button is clicked, the purchaseNFT() function is called on the contract with the sender's account address. Once the transaction is confirmed, the user is notified that the NFT was purchased and transferred to their wallet
*/
29 changes: 29 additions & 0 deletions contract/Payment.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract Payment is ERC721{
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;

address payable public owner;
mapping(address => uint256) public balances;

constructor(string memory name, string memory symbol) ERC721(name, symbol){
owner = payable(msg.sender);
}

function pay() public payable {
balances[msg.sender] += msg.value;
}

function purchaseNFT() public{
require(balances[msg.sender] >0, "INSUFFICIENT BALANCE");
_tokenIds.increment();
uint newItemId = _tokenIds.current();
_mint(msg.sender, newItemId);
balances[msg.sender] = 0;
}
}
Loading