event-ticketing-system-js-library
v0.2.8
Published
Library for event ticketing system
Downloads
11
Readme
ets-js-library
About
This is a JavaScript library for interacting with event ticketing system. It creates unsigned transactions and fetches data from smart contracts and ipfs.
How to use
Install:
npm i ets-js-library@npm:event-ticketing-system-js-library
Create event:
- Create an api token from nft.storage
- Import createEvent function from the library.
- Create metadata for the new event.
- Execute creteEvent function. This will return an unsigned transaction.
- Sign and send the transaction anyway you like.
import { createEvent } from "ets-js-library";
const metadata = {
name: "Event1",
eventId,
websiteUrl: "https://event1.com",
posterImageUrl: imageCidGatewayUrl,
date: {
start: Math.floor(Date.now() / 1000),
end: Math.floor(Date.now() / 1000) + 60 * 60,
},
location: {
country: "Bulgaria",
city: "Varna",
address: "Front Beach Alley, 9007 Golden Sands",
coordinates: {
latitude: "43.28365485346511",
longitude: "28.042738484752096",
},
},
ticketTypes: ["super early birds", "early birds", "regular", "onsite"],
maxTicketsPerAccount: 10,
contacts: "Contacts string",
status: "upcoming",
};
let key = "API key for NFT.storage";
let transaction = await createEvent(key, metadata, image, maxTicketsPerClient);
//You need to sign and send the transaction after this.
Update event:
- Create an api token from nft.storage
- Import updateEvent, getEventIpfsUri and deleteFromIpfs from the library.
- Create new metadata for the event.
- Execute getEventIpfsUri function. This will return the Uri of the current metadata.
- Execute updateEvent function. This will return an unsigned transaction.
- Sign and send the transaction anyway you like.
- If the transaction succeeds, you can safely delete the old metadata with deleteFromIpfs.
import { updateEvent, getEventIpfsUri, deleteFromIpfs } from "ets-js-library";
const metadata = {
name: "Event1",
eventId,
websiteUrl: "https://event1.com",
posterImageUrl: imageCidGatewayUrl,
date: {
start: Math.floor(Date.now() / 1000),
end: Math.floor(Date.now() / 1000) + 60 * 60,
},
location: {
country: "Bulgaria",
city: "Varna",
address: "Front Beach Alley, 9007 Golden Sands",
coordinates: {
latitude: "43.28365485346511",
longitude: "28.042738484752096",
},
},
ticketTypes: ["super early birds", "early birds", "regular", "onsite"],
maxTicketsPerAccount: 10,
contacts: "Contacts string",
status: "upcoming",
};
let key = "API key for NFT.storage";
let eventId = "Id of event in smart contract";
let metadataUri = await getEventIpfsUri(eventId);
try {
let transaction = await updateEvent(key, eventId, metadata, image);
//You need to sign and send the transaction here.
deleteFromIpfs(key, metadataUri);
} catch (error) {
console.log(error);
}
Remove event
- Create an api token from nft.storage
- Import removeEvent and deleteFromIpfs from the library.
- Execute removeEvent function. This will return an unsigned transaction.
- Sign and send the transaction anyway you like.
- If the transaction succeeds, you can safely delete the old metadata with deleteFromIpfs.
import { removeEvent, deleteFromIpfs } from "ets-js-library";
let key = "API key for NFT.storage";
let eventId = "Id of event in smart contract";
let metadataUri = await getEventIpfsUri(eventId);
try {
let transaction = await removeEvent(eventId);
//You need to sign and send the transaction here.
deleteFromIpfs(key, metadataUri);
} catch (error) {
console.log(error);
}
Fetch events by Ids
- Import fetchEvents from the library.
- Execute fetchEvents.
import { fetchEvents } from "ets-js-library";
//Ids of events in smart contract.
let eventIds = [1, 2, 3];
let events = fetchEvents(eventIds);
Fetch owned events
- Import fetchOwnedEvents function from the library.
- Execute fetchOwnedEvents by supplying an address.
import { fetchOwnedEvents } from "ets-js-library";
let address = "Address of events owner.";
let events = fetchOwnedEvents(address);
Fetch cached events from server
- You need to have JWT_SECRET first.
- Import fetchAllEventsFromServer function from the library.
- Create params.
- Execute fetchAllEventsFromServer.
import {fetchAllEventsFromServer} from 'ets-js-library';
let params = {
title: "",
description: "",
eventStartDateStartingInterval: "",
eventStartDateEndingInterval: "",
eventEndDateStartingInterval: "",
eventEndDateEndingInterval: "",
country: "",
place: "",
tags: "",
sort: "",
pagination: "",
organizer: "";
};
let events = fetchAllEventsFromServer(serverUrl, JWT_SECRET, params);
Add team member to event
- Import addTeamMember function from the library.
- Import utils function from ethers.
- Generate the hash of the role.
- Execute addTeamMember function. This will return an unsigned transaction.
- Sign and send the transaction anyway you like.
import { addTeamMember } from "ets-js-library";
import { utils } from "ethers";
let eventId = "Id of event in smart contract";
let address = "Address of new member.";
let role = utils.keccak256(utils.toUtf8Bytes("MODERATOR_ROLE"));
let transaction = await addTeamMember(eventId, role, address);
//You need to sign and send the transaction after this.
Remove team member from event
- Import removeTeamMember function from the library.
- Import utils function from ethers.
- Generate the hash of the role.
- Execute removeTeamMember function. This will return an unsigned transaction.
- Sign and send the transaction anyway you like.
import { removeTeamMember } from "ets-js-library";
import { utils } from "ethers";
let eventId = "Id of event in smart contract";
let address = "Address of team member.";
let role = utils.keccak256(utils.toUtf8Bytes("MODERATOR_ROLE"));
let transaction = await removeTeamMember(eventId, role, address);
//You need to sign and send the transaction after this.
Tests
Run tests:
npm run test
See test coverage:
npm run coverage
Conventions and standards
Commit message format
feat: Add beta sequence
^--^ ^---------------^
| |
| +-> Summary in present tense.
|
+-------> Type: chore, docs, feat, fix, refactor, style, or test.
Contributing
Please refer to each project's style and contribution guidelines for submitting patches and additions. In general, we follow the "fork-and-pull" Git workflow.
- Fork the repo on GitHub
- Clone the project to your own machine
- Commit changes to your own branch
- Push your work back up to your fork
- Submit a Pull request so that we can review your changes
NOTE: Be sure to merge the latest from "upstream" before making a pull request!