Contract templates
Contract templates determine the token the SDK uses and define the parameters of certain methods. The current contract templates:
The access control methods and royalties methods are used by all templates. The base ERC721 methods are used by the ERC721Mintable
and 721UserMintable
templates.
Access control methods
The following access control methods are administrative methods to control permissions for template token contracts.
addAdmin
Grants the admin
role to an address
Parameters
publicAddress
: string - the address to be elevated to admin
role
Response
transactionResponse
- confirmation the transaction was completed
Example
const adminadd = await existingContract.addAdmin({
publicAddress: process.env.WALLET_PUBLIC_ADDRESS,
});
console.log("new admin:", adminadd);
addMinter
Grants the minter
role to an address
Parameters
publicAddress
: string - the address to be elevated to minter
role
gas
: string - (optional) the gas price
Response
transactionResponse
- confirmation the transaction was completed
Example
const minteradd = await existingContract.accessControl.addMinter({
publicAddress: process.env.WALLET_PUBLIC_ADDRESS
gas: '5000'
});
console.log('new minter:', minteradd);
isAdmin
Checks if an address has an admin
role.
Parameters
publicAddress
: string - address of the account
Response
status
: boolean - returns true
if account has admin
rights.
Example
const isAdmin = await newContract.accessControl.isAdmin({
publicAddress: process.env.WALLET_PUBLIC_ADDRESS,
});
console.log(isAdmin);
isMinter
Checks if an address has an minter
role.
Parameters
publicAddress
: string - address of the account
Response
status
: boolean - returns true
if account has admin
rights.
Example
const isMinter = await newContract.accessControl.isMinter({
publicAddress: process.env.WALLET_PUBLIC_ADDRESS,
});
console.log(isMinter);
removeAdmin
Removes the admin
role from an address. Only callable by addresses with admin
rights.
Parameters
publicAddress
: string - address losing admin
role
Response
transactionResponse
: confirmation the transaction was completed
Example
const remove = await existingContract.accessControl.removeAdmin({
publicAddress: process.env.WALLET_PUBLIC_ADDRESS,
});
console.log(remove);
removeMinter
Removes the minter
role from an address. Only callable by addresses with admin
rights.
Parameters
publicAddress
: string - address losing minter
role
Response
transactionResponse
: confirmation the transaction was completed
Example
const remove = await existingContract.accessControl.removeMinter({
publicAddress: process.env.WALLET_PUBLIC_ADDRESS,
});
console.log(remove);
renounceAdmin
Removes the admin
role from an address. Only callable by address invoking the request.
Parameters
publicAddress
: string - address losing admin
role
Response
transactionResponse
: confirmation the transaction was completed
Example
const renounce = await existingContract.accessControl.renounceAdmin({
publicAddress: process.env.WALLET_PUBLIC_ADDRESS,
});
console.log(renounce);
renounceMinter
Removes the minter
role from an address. Only callable by address invoking the request.
Parameters
publicAddress
: string - address losing minter
role
Response
transactionResponse
: confirmation the transaction was completed
Example
const renounce = await existingContract.accessControl.renounceAdmin({
publicAddress: process.env.WALLET_PUBLIC_ADDRESS,
});
console.log(renounce);
renounceOwnership
Removes ownership of a smart contract from an address. This leaves the contract without an owner.
Parameters
contractAddress
: string - contract address of the smart contract being renounced
Response
transactionResponse
: confirmation the transaction was completed
Example
const renounceOwner = await existingContract.accessControl.renounceOwnership({
contractAddress: "0x5a5e0044123913dBFb32fB3706edFF5116D9B036",
});
console.log(renounceOwner);
Base ERC721 methods
The following methods are shared between the ERC721Mintable
template and ERC721UserMintable
template.
approveTransfer
Gives permission to transfer a token to another address.
Parameters
publicAddress
: string - address that will be approved to transfer
tokenId
: number - The NFT ID to transfer
Response
transactionResponse
- confirmation the transaction was completed
Example
const txApprove = await existingContract.approveTransfer({
to: "0x9daB8FcFe91688d360FeB9ba83F74F29dfC82287",
tokenId: 1,
});
await txApprove.wait();
console.log(txApprove);
setApprovalForAll
Gives full approval rights to a given address.
Parameters
to
: string - public address of the account to receive approval rights
approvalStatus
: boolean - set to true
to grant approval rights
Response
transactionResponse
: confirmation the transaction is complete
Example
const setApproval = await existingContract.setApprovalForAll({
to: publicAddress,
approvalStatus: true,
});
const approvalSet = await setApproval.wait();
console.log(approvalSet);
setContractURI
Sets the contractURI
metadata for the specified contract.
Parameters
contractAddress
: string - contract address to update
contractURI
: string - link to the JSON object containing metadata for the contract
Response
transactionResponse
: confirmation the transaction is complete
Example
const contractURI = await existingContract.setContractURI({
contractAddress: "0x9daB8FcFe91688d360FeB9ba83F74F29dfC82287",
contractURI:
"https://ipfs.io/ipfs/QmRfModHffFedTkHSW1ZEn8f19MdPztn9WV3kY1yjaKvBy",
});
console.log(contractURI);
transfer
Transfers the token from one address to another.
Parameters
from
: string - the public address of the one transferring the token
to
: string - the address receiving the token
tokenID
: number - the ID of the token being transferred
Response
transactionResponse
: confirmation the transaction is complete
Example
const txTransfer = await existing.transfer({
from: process.env.WALLET_PUBLIC_ADDRESS,
to: secondUser,
tokenId: 1,
});
const receipt = await txTransfer.wait();
console.log(receipt);
ERC1155Mintable template
Use the ERC1155Mintable
template to mint ERC-1155 tokens.
ERC1155Mintable
template parameters for the deploy
method:
baseURI
: string - baseURI of the contractcontractURI
: string - contractURI of the contractids
: array - IDs of valid tokens for the contractgas
: number - (optional) gas parameter to pass to transaction
The following methods are specific to ERC1155Mintable
.
addIds
Allows administrator of contract to add new valid token IDs.
Parameters
ids
: array - list of IDs to add
gas
: number - (optional) gas parameter to pass to transaction
Response
transactionResponse
: promise (object) - transaction information
Example
const existingContract = await sdk.loadContract({
template: TEMPLATES.ERC1155Mintable,
contractAddress: "0x5a5e0044123913dBFb32fB3706edFF5116D9B036",
});
const tx = await existingContract.addIds({
ids: [123, 1234],
});
mint
Mints a token.
Parameters
to
: string - destination address for the minted token
id
: number - ID of the token to mint
quantity
: number - quantity of the specified token to mint
gas
: number - (required for Polygon and Mumbai networks, optional for the other networks) gas parameter to pass to transaction
Response
transactionResponse
: confirmation the transaction was completed
Example
const mint = await existingContract.mint({
to: process.env.WALLET_PUBLIC_ADDRESS,
id: 1,
quantity: 10,
gas: 5000,
});
const minted = await mint.wait();
console.log(minted);
mintBatch
Mints multiple tokens for a publicAddress
.
Parameters
to
: string - destination address for the minted token
id
: array - array of the IDs of the token to mint
quantity
: number - quantity of the specified token to mint
gas
: number - (optional) gas parameter to pass to transaction
Response
transactionResponse
: confirmation the transaction was completed
Example
const mintBatch = await existingContract.mintBatch({
to: process.env.WALLET_PUBLIC_ADDRESS,
id: [1, 2, 3, 4, 5],
quantity: 10,
gas: 5000,
});
const minted = await mintBatch.wait();
console.log(minted);
setApprovalForAll
Gives full approval rights to a given address.
Parameters
to
: string - public address of the account to receive approval rights
approvalStatus
: boolean - set to true
to grant approval rights
gas
: number - (optional) gas parameter to pass to transaction
Response
transactionResponse
: confirmation the transaction is complete
Example
const setApproval = await existingContract.setApprovalForAll({
to: publicAddress,
approvalStatus: true,
gas: 5000,
});
const approvalSet = await setApproval.wait();
console.log(approvalSet);
setBaseURI
Sets the baseURI
metadata for the specified contract.
Parameters
baseURI
: string - baseURI of the contract
gas
: number - (optional) gas parameter to pass to transaction
Response
transactionResponse
: promise (object) - transaction information
Example
const baseURI = await sdk.setBaseURI({
baseURI: "ipfs://QmSA116Mqdxj5qx1cVpMrfkxhynft61jSYWvrfUawH5CYw/",
gas: 5000,
});
console.log(baseURI);
setContractURI
Sets the contractURI
metadata for the specified contract.
Parameters
contractURI
: string - link to the JSON object containing metadata for the contract
gas
: number - (optional) gas parameter to pass to transaction
Response
transactionResponse
: confirmation the transaction is complete
Example
const contractURI = await existingContract.setContractURI({
contractURI:
"https://ipfs.io/ipfs/QmRfModHffFedTkHSW1ZEn8f19MdPztn9WV3kY1yjaKvBy",
});
console.log(contractURI);
transfer
Transfers the token from one address to another.
Parameters
from
: string - the public address of the one transferring the token
to
: string - the address receiving the token
tokenID
: number - the ID of the token being transferred
quantity
: number - number of the given tokenId
to be transferred
gas
: number - (optional) gas parameter to pass to transaction
Response
transactionResponse
: confirmation the transaction is complete
Example
const txTransfer = await existing.transfer({
from: process.env.WALLET_PUBLIC_ADDRESS,
to: secondUser,
tokenId: 1,
quantity: 4,
gas: 5000,
});
const receipt = await txTransfer.wait();
console.log(receipt);
transferBatch
Transfers a batch of tokens from one address to another.
Parameters
from
: string - the public address of the one transferring the token
to
: string - the address receiving the token
tokenID
: array of integers - the IDs of the token being transferred
quantity
: array of integers - number of the given tokenId
to be transferred
gas
: number - (optional) gas parameter to pass to transaction
Response
transactionResponse
: confirmation the transaction is complete
Example
const txTransferBatch = await existing.transferBatch({
from: process.env.WALLET_PUBLIC_ADDRESS,
to: secondUser,
tokenId: [1, 2, 3]
quantity: [4, 5, 6]
gas: 5000,
});
const receipt = await txTransferBatch.wait();
console.log(receipt);
ERC721Mintable template
Use the ERC721Mintable
template to mint ERC-721 tokens.
ERC721Mintable
template parameters for the deploy method:
name
: string - name of the contractsymbol
: string - symbol of the contractcontractURI
: string - contractURI for the contract
The following methods are specific to ERC721Mintable
.
mint
Mints a token.
Parameters
publicAddress
: string - destination address for the token
tokenURI
: string - link to the JSON object containing metadata for the token
Response
transactionResponse
: confirmation the transaction was completed
Example
const mint = await existingContract.mint({
publicAddress: process.env.WALLET_PUBLIC_ADDRESS,
tokenURI:
"https://ipfs.io/ipfs/QmajL9pQBCMhvkwJdVYSBkMXaQnDdsMcEvKYSxmyUc5WYy",
});
const minted = await mint.wait();
console.log(minted);
ERC721UserMintable template
Use the ERC721UserMintable
template to mint ERC-721 tokens.
ERC721UserMintable
template parameters for the deploy
method:
name
: string - name of the contractsymbol
: string - symbol of the contractbaseURI
: string - baseURI for the contractmaxSupply
: string - maximum supply of tokens for the contractprice
: string - price to mint one token in EthermaxTokenRequest
: string - maximum tokens that can be requested per transaction
The following methods are specific to ERC721UserMintable
.
mint
Mints a token.
Parameters
quantity
: integer - the number to mint
cost
: string - Value (in Ether) of mint (cost per token * quantity)
Response
transactionResponse
: confirmation the transaction was completed
Example
const mint = await existingContract.mint({
quantity: 3,
cost: "0.00002",
});
const minted = await mint.wait();
console.log(minted);
price
Returns the value of the mint per token in Ether.
Parameters
none
Response
price
: number - value of the mint per token in ETH.
Example
const price = await sdk.price();
console.log(price);
reserve
Reserves (mints) an amount of tokens to the owner of the contract.
Parameters
quantity
: integer - quantity of tokens to mint to the owner (1-20)
Response
transactionResponse
: promise (object) - transaction information
Example
const reserve = await sdk.reserve({
quantity: 10,
});
console.log(reserve);
reveal
Sets the status of the contract to revealed
and sets the baseURI
.
Parameters
baseURI
: string - baseURI of the contract
Response
transactionResponse
: promise (object) - transaction information
Example
const reveal = await sdk.reveal({
baseURI: "ipfs://QmSA116Mqdxj5qx1cVpMrfkxhynft61jSYWvrfUawH5CYw/",
});
console.log(reveal);
setBaseURI
Sets the baseURI
metadata for the specified contract.
Parameters
baseURI
: string - baseURI of the contract
Response
transactionResponse
: promise (object) - transaction information
Example
const baseURI = await sdk.setBaseURI({
baseURI: "ipfs://QmSA116Mqdxj5qx1cVpMrfkxhynft61jSYWvrfUawH5CYw/",
});
console.log(baseURI);
setPrice
Sets the price (in Ether) of the mint.
Parameters
price
: string - price of the mint (per token) in Ether
Response
transactionResponse
: promise (object) - transaction information
Example
const price = await sdk.setPrice({
price: "0.00002",
});
console.log(price);
toggleSale
Toggles the sale status of the contract.
Parameters
none
Response
transactionResponse
: promise (object) - transaction information
Example
const sales = await sdk.toggleSale();
console.log(sales);
withdraw
Withdraws ether balance to owner address.
Parameters
none
Response
transactionResponse
: promise (object) - transaction information
Example
const withdraw = await sdk.withdraw();
console.log(withdraw);
Royalties methods
The following methods are relate to the royalties for the contract templates.
royaltyInfo
Returns receiver address and royalty amount based on sell price.
Parameters
tokenID
: number - Token ID
sellPrice
: number - Sell price of the token
Response
royaltyInfo
: object - results containing:
receiverAddress
: string - address to receive the royaltybigNumber
: number - Royalty amount
Example
const infos = await newContract.royaltyInfo({
tokenId: 1,
sellPrice: 100000,
});
console.log(infos);
setRoyalties
Sets the royalties for the receiver address.
Parameters
publicAddress
: string - address for the receiver
fee
: number - royalty fee to provide the receiver
Response
transactionResponse
: confirmation the transaction is complete
Example
const royalties = await newContract.setRoyalties({
publicAddress: process.env.WALLET_PUBLIC_ADDRESS,
fee: 50,
});
const royaltiesSet = await royalties.wait();
console.log(royaltiesSet);