Redeeming one's shares from a Melon fund is fairly simple. The first step is to create an instance of the Participation
contract.
This example requires an environment instance as described here.
import { Hub, Participation } from '@melonproject/melonjs';// your hub addressconst hubAddress = '0x05263237f43190ce0e93b48afb25dd60a03ad3c5';// declare an instance of the fund's hub to access the spoke contract addressesconst hub = new Hub(environment, hubAddress);// the address of the fund's participation contractconst participationAddress = hub.getRoutes().participation;// the address of the user making the redemption requestconst userAddress = '0xf039e6893ffa43196fd9d1d7038b74bf39dda4a5';// specify the gas price (refer to http://ethgasstation.info/).const gasPrice = 30000000000;// declare the instance of the fund's Participation contractconst participation = new Participation(environment, participationAddress);
From there, you can either redeem all shares:
const transaction = participation.redeem(userAddress);const opts = transaction.prepare({gasPrice});const receipt = transaction.send(opts);
Or redeem a specific amount of shares to redeem:
// a bignumber representing the number of shares to redeemconst shareQuantity = new BigNumber(329);const transaction = participation.redeemQuantity(userAddress, shareQuantity);const opts = transaction.prepare({gasPrice});const receipt = transaction.send(opts);