Move
Installation
Download @metaspacecy/information-sdk from npmjs. To start building, run below command in your project directory to install packages:
npm install @metaspacecy/infomation-SDK
or
yarn add @metaspacecy/infomation-SDK
Getting started
To get started, first create a new InformationSDK, using signAndSubmitTransaction function from specific wallet, the network chainID interacting to, and the parameters expected in return(Ex. hash, eventId, creator, startTime, etc.)
// import SDK
import InformationSDK from "metaspacecy-aptos-prediction";
// signAndSubmitTransaction is function of wallet adapter
// ChainID of the network used by the user
// The third parameter takes an array of values that the user wants to return after using the signAndSubmitTransaction function
// example ["hash"] => result {hash: ...}
const informationSDk = new InformationSDK(
signAndSubmitTransaction,
chainID,
["hash"]
);
Get operator role
To create an event in the information market, users are required to be played a “operator role”. Simply call below function with the current signer to get the role for the sender. Later on this sender can create many events desired. This is one time transaction that means only one in the life time.
informationSDk.getOperatorRole()
Create an event
There are 3 types of events available in the Information market:
Predict
Survey
Survey with nft
Example: create an predict event by using following function.
informationSDk.createPredictEvent(
description,
uri,
options,
startTime,
endTime,
payoutTime,
coinType
);
Parameters:
description - String: the description of the future event.
uri - String: the external link to the event media.
options - Array: the set of possible option that the event is expected to occur.
startTime - Number: the start time of the event in seconds.
endTime - Number: the end time of the event in seconds.
payoutTime - Number: the extended time for the event creator finalise the outcomes.
coinType - String: the coin type of the collateral required as taking part in the event.
Note: The creator has to pay an entry fee for creating the event. So make sure that creator has enough sufficient fund. See more details in the Metaspacecy docs.
Returns
The transaction will return the 32 bytes transaction hash and other information related to event detail.
Cancel an event
You can cancel the event before it starts.
informationSDk.cancelSurveyEvent(event_description, event_options, coinType);
Parameters:
event_description - String: the description of the future event.
event_options - Array: the set of possible option that the event is expected to occur.
coinType - String: the coin type of the collateral required as taking part in the event.
Predict an event
Participating in the predict event requires satisfying certain conditions:
informationSDk.predictEvent(option, amount, event_creator, event_description, event_options, coinType);
Parameters:
option - String: the option expected to occur in the end of the event.
amount - Number: the number of collateral committed to the event.
event_creator - String: the address of the event creator.
event_description - String: the description of the event.
options - Array: the set of possible option that the event is expected to occur.
coinType - String: the coin type of the collateral required as taking part in the event.
Finalize an event
After the event ends, the event creator must proceed to finalize the event and provide the outcomes. The outcomes is an array containing the proportions of each options.
informationSDk.finalizePredictEvent(event_description, event_options, outcomes, coinType);
Parameters:
event_description - String: the description of the event.
event_options - Array: the set of possible option that the event is expected to occur.
outcomes - Array: the outcomes of the event in the end.
coinType - String: the coin type of the collateral required as taking part in the event.
Redeem an event
After the creator has finalized, users must wait until the payoutTime expired to proceed with redeeming.
informationSDk.redeemPredictEvent(token_name, amount, coinType);
Parameters:
token_name - String: the name of derivative token generated from the event.
amount - Number: the number of collateral committed to the event.
coinType - String: the coin type of the collateral required as taking part in the event.
Get information
Get token balance of a user.
Get event detail by eventID.
Get all of events created by a creator.
Get all of events predicted by a user.
Demo:
You can refer to the example in the file examples/nextjs-example
Connect wallet
Get Operator role
Create Event
Predict Event
You can see the NFT created after predicting in your wallet.
Finalize Event
Redeem Event
Additionally, we will place auxiliary functions in the 'More Actions' tab.
Last updated