EVM
Installation
We recommend using nvm to manage Node.js versions. Execute nvm use
, if you have nvm
installed. To start building, run below command in your project directory to install packages:
npm install @metaspacecy/information-SDK
or
yarn add @metaspacecy/information-SDK
Getting Started
To get started, first create a new InformationSDK instance with constructor of network provider and chainId.
Through a browser provider (Metamask, Coinbase …)
import { InformationSDK, Network } from "@metaspacecy/information-sdk/evm";
import { ethers } from "ethers";
const provider = new ethers.providers.Web3Provider(window.ethereum);
const informationSdk = new InformationSDK(provider, Network.bnbTestnet);
Through a RPC Provider (Alchemy, Infura …)
import { InformationSDK, Network } from "@metaspacecy/information-sdk/evm";
import { ethers } from "ethers";
const provider = new ethers.providers.JsonRpcProvider("<https://<network>.alchemyapi.io/v2/YOUR-API-KEY>");
const informationSdk = new InformationSDK(provider, Network.bnbTestnet);
With custom signer
import { InformationSDK, Network } from "@metaspacecy/information-sdk/evm";
import { ethers } from "ethers";
const provider = new ethers.providers.JsonRpcProvider("<https://<network>.alchemyapi.io/v2/YOUR-API-KEY>");
const signer = new ethers.Wallet("YOUR_PK", provider);
const informationSdk = new InformationSDK(signer, Network.bnbTestnet);
Parameters:
provider - JsonRpcProvider | Signer: a valid network provider.
network - Number: the network chainId.
config - ConfigExpand: customizable config.
Use cases
Getting 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.
const result = await informationSdk.registerOperator()
Create an event
informationSdk.createEvent(eventName, options, paymentToken, creatorFee, startTime, endTime, payoutTime);
Will send a transaction to the smart contract and execute its method. Note this can alter the smart contract state.
Parameters:
eventName - String: the description of the future event.
options - Array: the set of possible option that the event is expected to occur.
paymentToken - String: address of the collateral required as taking part in the event.
creatorFee - Number: the basic points charged for participants and are paid to the event creator. Maximum is 10 bps.
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.
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.
Example:
const event = await informationSdk.createEvent(
"Champions League Winner?",
["Manchester City", "Inter Milan"], "0x0000000000000000000000000000000000000000",
5,
1684467186,
1684468186,
60
);
{
description: "Champions League Winner?",
options: ["Manchester City", "Inter Milan"],
creator: "0x5A5316f2619BF119c2FB2230669b1A4c5a707279",
paymentToken: "0x0000000000000000000000000000000000000000",
creatorFee: 5,
startTime: 1684546822,
endTime: 1684931298,
extraTime: 60,
txHash: '0x0baa4272a6248064135e8eacd9ca0bcd20f6107e53094c191192e99780776cbe', eventId: 10
}
Predict an event
informationSdk.predictEvent(eventId, option, amount);
Will send a transaction to the smart contract and execute its method. Note this can alter the smart contract state.
Parameters:
eventId - Number: the event ID.
option - Number: the index of the option in the event’s options array.
amount - Number: the number of collateral committed to the event.
Example:
const predictDetail = await informationSdk.predictEvent(1, 1, 0.001);
Resolve an event
informationSdk.resolveEvent(eventId, outcomes);
Will send a transaction to the smart contract and execute its method. Note this can alter the smart contract state.
Parameters:
eventId - Number: the event ID.
outcomes - Array: the outcomes of the event in the end.
Note : Only creator can resolve event.
Example:
const resolveDetail = await informationSdk.resolveEvent(1, [100, 0]);
Redeem events
informationSdk.redeemEvent(eventId, option, amount);
Will send a transaction to the smart contract and execute its method. Note this can alter the smart contract state.
Parameters:
eventId - Number: the event ID.
option - Number: the index of the option in the event’s options array.
amount - Number: the number of derivative generated from the event to redeem reward.
Example:
const resolveDetail = await informationSdk.redeemEvent(1, 1, 0.001);
Get all of events created by a creator
Will return array events created by the creator.
Parameters:
creatorAddress - String: address of the creator.
Example:
Note: in order to instantly get data, recommend config apiKeyNetwork in constructor of instance InformationSDK.
Get all of events predicted by a user
Will return array events predicted by the user.
Parameters:
userAddress - String: address of the user.
Note: in order to instantly get data, recommend config apiKeyNetwork in constructor of instance InformationSDK.
Example:
Last updated