Skip to content

Backend server created in Golang to provide an API interface for interaction with Database

License

Notifications You must be signed in to change notification settings

NiftyRewards/nifty-rewards-backend

Repository files navigation

NiftyRewards Server

Backend server created in Golang to provide an API interface for interaction with Database.

Database Design

database-design

Entities

Merchants (merchant_id, merchant_name)

NFTs (collection_address, collection_name, totalSupply)

Users (address_w3a, address_b)


Relationships

Campaign (campaign_id, merchant_id, collection_address, start_time, end_time)

Rewards (rewards_id, merchant_id, collection_address, token_id, description, quantity, quantity_used, approved)

Endpoints

User


[POST] ✅/users/bind/{address_w3a}/{address_to_bind}

Maps the web3Auth wallet address to a wallet that the user owns (one that is used to collect NFTS for example)

AUTH: Caller must be the owner of the account associated to address_w3a

Replaces current binded wallet with address_to_bind.


[GET] /user/nfts/{address_w3a}

Gets all the NFTS

Returns a list of user’s NFTS in the wallet.

Data is populated from request to Tatum


[GET] ✅/user/rewards/{merchant_id}

Gets all the rewards available filtered by the merchant_id

Returns a list of user’s NFTS in the wallet.

Data is populated from request to Tatum

[https://apidoc.tatum.io/#operation/NftGetTokensByAddressErc721]

[PUT] ✅/user/redeem/{rewards_id} Redeems rewards based on rewards_id

Only owner of rewards_id can redeem

returns:
200: Success
400: User is not the owner of reward_id = {reward_id}
400: Reward Id does not exist
400: Reward has been fully redeemed

Reduce quantity by 1, quantity cannot fall below 0 Increase quantity_used by 1



Merchant

[GET] ✅/merchants

Get list of merchants.

returns:
merchants: Mechant[]

[POST] ✅/merchant/startcampaign

Request to start a campaign with a collection.

Reward {
  description: String
  quantity: Number
}

body:
{
	"merchant_id": 2,
	"collection_address": "0x123",
	"rewards": [{
			"description": "first_reward",
			"quantity": 4
		},
		{
			"description": "second_reward",
			"quantity": 5
		},
		{
			"description": "third_reward",
			"quantity": 3
		}
	]
}
- Collection owner gets account address of the merchant
- Collection owner logs into the web app
- Collection owner goes to “approve merchant” page
- Collection owner inputs merchant address collected in step 1 & collection address
- Collection owner signs an typed sign with the merchant address and collection address
- Backend verifies if the collection owner is indeed the ownerOf collection address
- If ownerOf() Collection address is equals to the recovered address of the signature, the collection will be binded.

[GET] ✅/merchant/campaigns/{merchant_id} Retrieves all campaigns that a merchant has

returns:
campaigns: Campaign[]


Collection Owner

[POST] ✅/collectionowner/add

Adds collection to merchant. Only owner of collection can do this The owner of the collection will be able to approve the merchant to use it to apply discounts. Approval can only happen after merchant has requested for a collaboration

body:
merchant_id: Int
collection_address: String
signature: String

{
	"collection_address": "0xCryptoPunks",
	"merchant_id": 1,
	"start_time": 1650732173,
	"end_time": 1650732174
}

returns:
200: Successfully approved campaign
400: Signer is not the collection owner
400: Collection does not exist
400: Invalid Signature
400: No pending campaign

User Flows

User Account Registration (Existing NFT Holder)

user-registration-existing

User Account Registration (New to NFTs)

user-registration-new

User Reward Redemption

user-reward-redemption

Merchant Account Registration

merchant-registration

Merchant - Start a Campaign

merchant-start-campaign

Collection Owner - Approve a Campaign

collectionowner-approve-compaign

Sponsor Challenges

Web3Auth

We are exclusively using Web3Auth as the main mode of login and authentication for our application. Using Web3Auth, we are able to allow users to easily on-board our platform with a crypto wallet, letting them directly have access to purchase NFTs that have loyalty rewards.

We improve the current system by creating a binding/mapping feature that binds existing wallets to the Web3Auth account. This is useful for users who already have NFTs in another wallet.

About

Backend server created in Golang to provide an API interface for interaction with Database

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published