Frontend Integration

Index is a Singleton Contract providing all the needed APIs to mint and burn indexes. It can be found at the following links for mainnet and ropsten.

You can find all the needed ABIS here.

Create New Index Token

var indexAddress = "0x3a6A5fCcE56Fa57eEB4B24aeb8d13A2e3197B333";

var indexContract = new web3.eth.Contract(abis.IndexABI, indexAddress);

var name = "My Awesome Index";
var symbol = "MAI";
var uri = "https://ipfs.io/ipfs/....";

var tokensAddresses = [
    "0x7b123f53421b1bf8533339bfbdc7c98aa94163db",
    "0x34612903db071e888a4dadcaa416d3ee263a87b9",
    "0x0000000000000000000000000000000000000000"//Ethereum
];

var amounts = [
    3 * 1e18,
    2 * 1e18,
    0.01 * 1e18
];

var transaction = await indexContract.methods.mint(name, symbol, uri, tokensAddresses, amounts, 0, myAddress).send();
transaction = await web3.eth.getTransactionReceipt(transaction.transactionHash);
var event = web3.utils.sha3("NewIndex(uint256,address,address,uint256)");
var objectId = transaction.logs.filter(it => it.topics[0] === event)[0].topics[1];
objectId = web3.eth.abi.decodeParameter("uint256", objectId);

Mint Index Tokens

var amountToMint = 2 * 1e18;

var data = await indexContract.methods.info(objectId, amountToMint).call();

tokensAddresses = data[0];
amounts = data[1];

var tokens = tokensAddresses.map(address => new web3.eth.Contract(abis.IERC20ABI, address));

var value = 0;

for(var token of tokens) {
    var amount = amounts[tokenAddresses.indexOf(token.options.address)];
    if(token.options.address === '0x0000000000000000000000000000000000000000') {
        value = amount;
        continue;
    }
    await token.methods.approve(indexAddress, amount);
}

await indexContract.methods.mint(objectId, amountToMint, myAddress).send({value});

Burn Index Tokens

var indexCollectionAddress = await indexContract.methods.collection().call();

var indexCollection = new web3.eth.Contract(abis.IETHItemABI, indexCollectionAddress);

var amountToBurn = 0.5 * 1e18;

await indexCollection.methods.safeTransferFrom(myAddress, indexAddress, objectId, amountToBurn, "0x");

Last updated