Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding token #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"homepage": "https://github.com/paytweed/backend-sdk-nodejs-example#readme",
"dependencies": {
"@paytweed/backend-sdk": "1.0.4",
"@paytweed/backend-sdk": "^2.0.0",
"cors": "2.8.5",
"express": "4.18.2"
},
Expand Down
2 changes: 1 addition & 1 deletion src/auth.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class AuthService {
_userId = "xxxx"
_userId = "xxxx999"
_userEmail = "[email protected]"

getAuthUser() {
Expand Down
2 changes: 2 additions & 0 deletions src/constants/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const collectionsData = {
ethereumSepolia: {
contractAddress: "0xfae681f31e7a89c195fa3b1d16af351b9facc5b8",
abi: "safeMint(toAddress address, tokenUri string)",
tokenAddress: "0x3Ee449A38Ef7f51073df49Bc62c42Ab0DdF025df",
tokenAbi: "mint(toAddress address, amount uint256)"
},
polygonMumbai: {
contractAddress: "0xebe81fd78bd43873bcd30cb7312b75468686cc4f",
Expand Down
48 changes: 30 additions & 18 deletions src/nft.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const collectionsData = require("./constants/collections")

class NftService {
constructor(blockchainId = "ethereumSepolia") {
constructor(blockchainId = "bnbTestnet") {
this.blockchainId = blockchainId;
}

Expand All @@ -17,30 +17,42 @@ class NftService {
this.blockchainId = blockchainId;
}

/**
* an example to an NFT checkout with the following mint function:
* safemint(toAddress address, tokenId uint256) payable public
* The abi should be taken from the compiled NFT contract
* The params should be populated in the customMintParams object
* There are two parameters that are getting populated from the frontend: toAddress and tokenURI
**/
getById(id) {
getTokenById(id) {
console.log("Getting token by ID");
return {
nftId: id,
priceInCents: this._getNftPrice(),
tokenUri: "https://tweed-demo.web.app/tweedNft.png",
tokenId: "1",
priceInCrypto: 1000000000000000,
thumbnailPath: "https://png.pngtree.com/png-clipart/20230329/ourmid/pngtree-money-bag-cartoon-coins-png-image_6671982.png",
fiatCurrencyId: "USD",
contractAddress: collectionsData[this.blockchainId].contractAddress,
contractAddress: collectionsData[this.blockchainId].tokenAddress,
chain: this.blockchainId,
title: "NFT_TITLE",
description: "NFT_DESCRIPTION",
// abi: "mint(toAddress address, tokenUri string)", //you have the option to use function signature of ABI or the longer version below
abi: collectionsData[this.blockchainId].abi,
title: "TOKEN_TITLE",
description: "TOKEN_DESCRIPTION",
abi: collectionsData[this.blockchainId].tokenAbi,
customMintParams: {
tokenId: id,
toAddress: "0x0b0691967454Dfe32662100614585AaB7d17AC32",
amount: "1"
},
};
}

getNFTById(id) {
console.log("Getting NFT by ID");
return {
nftId: id,
priceInCents: this._getNftPrice(),
tokenUri: "https://tweed-demo.web.app/tweedNft.png",
fiatCurrencyId: "USD",
contractAddress: collectionsData[this.blockchainId].contractAddress,
chain: this.blockchainId,
title: "NFT_TITLE",
description: "NFT_DESCRIPTION",
abi: collectionsData[this.blockchainId].abi,
customMintParams: {
tokenId: id,
},
};
}
}

module.exports = new NftService();
7 changes: 4 additions & 3 deletions src/tweed.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ const nftService = require("./nft.service");
class TweedService {
async initialize() {
this._client = await TweedBackendSDK.setup({
apiKey: "YOUR-API-KEY",
apiSecret: "YOUR-API-SECRET",
apiKey: "<YOUR_API_KEY>",
apiSecret: "<YOUR_API_SECRET>",
defaultBlockchainIds: ["ethereumSepolia"],
callbacks: {
getNftPurchaseData: async ({ nftId }) => nftService.getById(nftId),
getNftPurchaseData: async ({nftId}) => nftService.getNFTById(nftId),
getTokenPurchaseData : async({tokenId}) => nftService.getTokenById(tokenId)
},
});
return this._client;
Expand Down
Loading