0.0.1 • Published 6 months ago

@punkcodeprotocol/sdk v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

🚀 MetaToken SDK

TOC

📌 Overview

📥 Installation & Setup

npm i metatoken_sdk

📝 How to use MetaTokenSDK? Refer to this example

1. Deploy your Avatar and Weapon

import { MetaTokenDeployer } from "metatoken_sdk";
const ethProvider = ethers.getDefaultProvider("goerli"); // goerli testnet 
const signer = new ethers.Wallet(key, provider);

// deploy your Avatar
let deployTx = await MetaTokenContract.deployDefault({
    chainId: chainId,
    runner: signer,
    name: "Avatar",
    symbol: "AV",
});
const avatarContract = deployTx.metaTokenContract;

// deploy your Weapon
deployTx = await MetaTokenContract.deployDefault({
    chainId: chainId,
    runner: signer,
    name: "Weapon",
    symbol: "WP",
});
const weaponContract = deployTx.metaTokenContract;
FunctionParameterParameter Descriptiontype
deployDefaultsignerethers signersigner
chainIdchainId of networknumber
namethe name of MetaTokenstring
symbolthe symbol of MetaTokenString

2. Deploy your PropertyFactory

deployTx = await PropertyFactory.deployDefault({
    chainId: chainId,
    runner: signer,
    name: "PropertyFactory",
    uri: "<propertyURI>",    
});
const propertyFactoryContract = deploy.propertyFactory;
FunctionParameterDescriptiontype
deployDefaultsignerethers signersigner
chainIdchainId of networknumber
namethe name of MetaTokenstring
urithe uri of MetaTokenstring

3. Mint MetaToken and construct.

const mintAvatarTx = await avatarContract.mint({to: "<to_address>"});
// first avatar
const avatar00 = new MetaToken({
    tokenAddress: avatarContract.tokenAddress,
    tokenId: mintTx.metaTokenId,
    chainId: chainId,
    signer: signer,
});

const mintWeaponTx = await avatarContract.mint({to: await avatar00.getTokenBoundAccount()});
// first weapon
const weapon00 = new new MetaToken({
    tokenAddress: weaponContract.tokenAddress,
    tokenId: mintWeaponTx.metaTokenId,
    chainId: chainId,
    signer: signer,
});
FunctionParameterParameter Descriptiontype
minttothe address of someone you want to sendString
FunctionParameterParameter Descriptiontype
constructtokenAddressthe address of MetaTokenstring
tokenIdthe id of MetaToken you mintnumber
chainIdchainIdnumber
signerethers signersigner

4. Setup EventUp & EventDown.

Metatoken can only add tokens from the eventup, and Metatoken can only be added by tokens from the eventdown list

const setEventsUpTx = await avatar00.getContract().connect(signer).setEventsUp({eventUps:['<weaponTokenAddress>']})
const setEventsDownTx = await weapon00.getContract().connect(signer).setEventsDown({eventDowns:['<avatarTokenAddress>']})
FunctionParameterParameter Descriptiontype
setEventsUpeventUpslist of address you want the MetaToken can be addedlist
setEventsDowneventDownslist of address you want the MetaToken can addlist

5. Control your Weapon with your Avatar

You can add weapon, remove weapon, replace them.

Note Make sure your Avatar's TokenBoundAccount owns the Weapon

// you can add child for your token
await avatar00.addChild({
    childToken: {
        tokenAddress: weapon.tokenAddress,
        tokenId: weapon.tokenId,
    },
});
// you can serach your childs
await avatar00.getChilds(); 
// you can search your parent
await weapon00.getParent();
// you can remove child for your token
await avatar00.removeChild({
    waitRemoveChildTokenIndex: 0,
})
// you can replace child for your token
await avatar00.batchReplaceChild({
    waitAddChildTokens: [
        {
            tokenAddress: "<WeaponAddress>",
            tokenId: "<anotherTokenId>",
        },
    ],
    waitRemoveChildTokenIndex: [0],
});
StructureParameterParameter DescriptionType
childToken/waitAddChildTokenstokenAddressToken addressaddress
tokenIdToken idint
FunctionParameterParameter Description
addChildchildTokentoken info you want to add
removeChildwaitRemoveChildTokenIndexindex of token you want to remove from MetaToken
batchReplaceChildwaitAddChildTokenstoken info list you want to add
waitRemoveChildTokenIndexindex of token you want to remove from MetaToken
getChilds
getParent

7. Setup global property

This function is used to configure global properties, as example, we configure "ATTACK" and "Defend" as our default properties.

// add global property (Attack and Defend)
await propertyFactoryContract.addGlobalProperty({property:["ATK", "DEF"]});
console.log(await propertyFactoryContract.queryGlobalProperty());
// output: [ 'ATK', 'DEF' ]
FunctionParameterParameter DescriptionType
addGlobalPropertypropertyproperty listlist

8. Register PropertyFactory for your Avatar and Weapon

By register PropertyFactory for your MetaToken, you can manage the properties available for Metatoken with the PropertyFactory.

// register avatar
await avatarContract.setUpPropertyFactory({
    factoryAddress: propertyFactoryContract.implementationAddress,
});
// register weapon
await weaponContract.setUpPropertyFactory({
    factoryAddress: propertyFactoryContract.implementationAddress,
});
FunctionParameterParameter DescriptionType
setUpPropertyFactoryfactoryAddressproperty factory implement addressstring

9. Setup Avatar's property and Weapon's property

Configure the properties available for Metatoken.

// add atk and def for avatar
await propertyFactoryContract.setPropertyFor({
    tokenAddress: avatar.tokenAddress,
    propertyIndex: [0, 1],
});
// add atk for avatar
await propertyFactoryContract.setPropertyFor({
    tokenAddress: weapon.tokenAddress,
    propertyIndex: [0],
});
FunctionParameterParameter DescriptionType
setPropertyFortokenAddressMetaToken implement addressstring
propertyIndexindex of propertylist

10. Mint property for your Avatar and Weapon

// add 100 atk to avatar
await propertyFactoryContract.mintProperty({
    to: (await avatar00.getTokenBoundAccount()).address,
    propertyIndex: 0,
    amount: 100,
    data: "0x",
});
// add 50 def to avatar
await propertyFactoryContract.mintProperty({
    to: (await avatar00.getTokenBoundAccount()).address,
    propertyIndex: 1,
    amount: 100,
    data: "0x",
});
// add 45 atk to weapon
await propertyFactoryContract.mintProperty({
    to: (await weapon00.getTokenBoundAccount()).address,
    propertyIndex: 0,
    amount: 100,
    data: "0x",
});
FunctionParameterParameter DescriptionType
mintPropertytoto addressstring
propertyIndexindex of propertynumber
amountamountnumber
data(optional)call datahex string

11. Now you can search your Avatar's property and Weapon's property

await propertyFactoryContract.propertiesOf({ tokenAddress: avatar00.tokenAddress, tokenId:0 }),
await propertyFactoryContract.propertiesOf({ tokenAddress: weapon00.tokenAddress }),
FunctionParameterParameter DescriptionType
propertiesOftokenAddresstokenAddressstring
tokenId(optional)tokenIdnumber

12. We also support ERC6551

You can learn how to use TokenBound here.

0.0.1

6 months ago