👨‍💻How to use the libraries

Deployments

List of deployed Registries per network can be found here.

Installation

npm i @zero-labs/smart-contracts

Setup

import { CertificateContracts } from '@zero-labs/smart-contracts';

...

const provider = new providers.JsonRpcProvider('https://volta-rpc.energyweb.org'); // Replace with your RPC node of choice
const signer = new Wallet('0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1', provider); // Replace with your private key for deployment


const certificateContracts = new CertificateContracts(signer);
await certificateContracts.deploy(
    1 // (OPTIONAL): Replace with your desired topic of choice, otherwise the next available topic will be assigned to you
);

const {
    registry, // Registry smart contract
    batches, // Batches smart contract
    topic // Topic under which the certificates would be minted
} = certificateContracts;    

Usage

Creating an empty batch

await batches.createBatches(1);

Setting an redemption statement for a batch

await batches.setRedemptionStatement(
    batchId,
    "REDEMPTION_STATEMENT_ID-123",
    "https://test.uri/1"
)

Minting tokens

import { encodeMetadata } from '@zero-labs/smart-contracts';
import { BigNumber } from 'ethers';
import { DateTime } from 'luxon';

await batches.mint(
    '1', // Batch ID
    ['0xd46aC0Bc23dB5e8AfDAAB9Ad35E9A3bA05E092E8'], // Mint TO
    [1e6], // Amount
    [encodeMetadata({
        generator: {
            id: "123",
            name: "Ime",
            energySource: "SOLAR",
            region: "EU",
            country: "HR",
            capacity: BigNumber.from(1e9),
            commissioningDate: BigNumber.from(
                DateTime.fromISO("2017-05-15").valueOf()
            ),
        },
        generationStartTime: BigNumber.from(
            DateTime.fromISO("2022-01-01").valueOf()
        ),
        generationEndTime: BigNumber.from(DateTime.fromISO("2022-01-31").valueOf()),
        productType: "I-REC",
        data: '',
    })]
);

Transferring the tokens

import { utils } from 'ethers';

await registry.safeTransferFrom(
    '0xD173313A51f8fc37BcF67569b463abd89d81844f', // FROM
    '0xd46aC0Bc23dB5e8AfDAAB9Ad35E9A3bA05E092E8', // TO
    '1', // CERTIFICATE ID
    1e6, // AMOUNT
    utils.solidityPack(['uint256'], [TransactionType.TRANSFER]), // Needed as metadata to differentiate the call as a transfer
);

Claiming the tokens

import { encodeClaimData } from '@zero-labs/smart-contracts';

await registry.safeTransferAndClaimFrom(
    '0xD173313A51f8fc37BcF67569b463abd89d81844f', // FROM
    '0xd46aC0Bc23dB5e8AfDAAB9Ad35E9A3bA05E092E8', // TO
    '1', // CERTIFICATE ID
    1e6, // AMOUNT
    '', // Additional claiming metadata, unused for now
    encodeClaimData({
        beneficiary: "Test beneficiary",
        region: "string",
        countryCode: "string",
        periodStartDate: "string",
        periodEndDate: "string",
        purpose: "string",
        consumptionEntityID: "string",
        proofID: "string",
    })
);

Last updated