ERC-20 tokens minting
ERC-20 tokens minted by the interface of Dev Protocol have an extended interface that supports staking, revenue sharing, etc., and are referred to in the whitepaper as Property Tokens.
Mint ERC-20 tokens
Immediately mint your ERC-20 tokens by executing create
function of PropertyFactory contract.
create
function takes 3 arguments:
- Token name
- Token symbol
- Author address
Token name/symbol are mapped to the token name/symbol of the newly minted ERC-20 tokens. The author address must be the same address as the transaction sender for later ownership authentication and ERC-721 token customization.
- Dev Kit JS
- Polygon/Arbitrum and their testnets
- Ethereum
import { clientsPropertyFactory } from '@devprotocol/dev-kit'
import { whenDefined } from '@devprotocol/util-ts'
import type { BaseProvider } from '@ethersproject/providers'
// This function mints an ERC-20 tokens with hard-coded options, and returns the new token address.
export default (provider: BaseProvider) => {
const clients = await clientsPropertyFactory(provider)
const propertyFactory = whenDefined(clients, ([l1, l2]) => l1 ?? l2)
const tokenAddress = await whenDefined(propertyFactory, (contract) =>
contract.create(
// Token name
'My Token',
// Token symbol
'MYT',
// Author address
'0xDbc05b1eCB4fdaEf943819C0B04e9ef6df4bAbd6'
)
)
return tokenAddress
}
clientsPropertyFactory
detects chains from a given provider and returns an array of contract instances. The first element of the array is the mainnet (v1 interface) contract and the second element of the array is the L2 (v2 interface) contract.
import "@devprotocol/protocol-v2/contracts/interface/IPropertyFactory.sol"
contract MyContract {
IPropertyFactory public propertyFactory;
constructor(address _propertyFactory) public {
propertyFactory = IPropertyFactory(_propertyFactory);
}
// This function mints an ERC-20 tokens with hard-coded options, and returns the new token address.
function mint() external returns(address) {
address tokens = propertyFactory.create(
// Token name
"My Token",
// Token symbol
"MYT",
// Author address
"0xDbc05b1eCB4fdaEf943819C0B04e9ef6df4bAbd6"
);
return tokens;
}
}
See Ecosystem Addresses for PropertyFactory contract addresses.
import "@devprotocol/protocol/contracts/interface/IPropertyFactory.sol"
import "@devprotocol/protocol/contracts/interface/IAddressConfig.sol"
contract MyContract {
IAddressConfig public addressConfig;
constructor(address _addressConfig) public {
addressConfig = IAddressConfig(_addressConfig);
}
// This function mints an ERC-20 tokens with hard-coded options, and returns the new token address.
function mint() external returns(address) {
IPropertyFactory propertyFactory = IPropertyFactory(addressConfig.propertyFactory());
address tokens = propertyFactory.create(
// Token name
"My Token",
// Token symbol
"MYT",
// Author address
"0xDbc05b1eCB4fdaEf943819C0B04e9ef6df4bAbd6"
);
return tokens;
}
}
See Ecosystem Addresses for AddressConfig contract addresses.
Mint and authentication
To mint a tokens and authenticate at the same time, use the createAndAuthenticate
function.
createAndAuthenticate
function takes 6 arguments:
- Token name
- Token symbol
- Market address
- First argument to pass through to Market
- Second argument to pass through to Market
- Third argument to pass through to Market
- Dev Kit JS
- Polygon/Arbitrum and their testnets
- Ethereum
import { clientsPropertyFactory } from '@devprotocol/dev-kit'
import { whenDefined } from '@devprotocol/util-ts'
import type { BaseProvider } from '@ethersproject/providers'
// This function mints and authenticate an ERC-20 tokens with hard-coded options, and returns the transaction fail/success.
export default (provider: BaseProvider) => {
const clients = await clientsPropertyFactory(provider)
const propertyFactory = whenDefined(clients, ([l1, l2]) => l1 ?? l2)
const result = await whenDefined(propertyFactory, (contract) =>
contract.createAndAuthenticate(
// Token name
'My Token',
// Token symbol
'MYT',
// Market address
'0xDbc05b1eCB4fdaEf943819C0B04e9ef6df4bAbd6',
// Three argument to pass through to Market
['arg1', 'arg2', 'arg3']
)
)
return result
}
clientsPropertyFactory
detects chains from a given provider and returns an array of contract instances. The first element of the array is the mainnet (v1 interface) contract and the second element of the array is the L2 (v2 interface) contract.
import "@devprotocol/protocol-v2/contracts/interface/IPropertyFactory.sol"
contract MyContract {
IPropertyFactory public propertyFactory;
constructor(address _propertyFactory) public {
propertyFactory = IPropertyFactory(_propertyFactory);
}
// This function mints and authenticate an ERC-20 tokens with hard-coded options, and returns the transaction fail/success.
function mint() external returns(bool) {
bool result = propertyFactory.createAndAuthenticate(
// Token name
"My Token",
// Token symbol
"MYT",
// Market address
"0xDbc05b1eCB4fdaEf943819C0B04e9ef6df4bAbd6",
// First argument to pass through to Market
"arg1",
// Second argument to pass through to Market
"arg2",
// Third argument to pass through to Market
"arg3"
);
return result;
}
}
See Ecosystem Addresses for PropertyFactory contract addresses.
import "@devprotocol/protocol/contracts/interface/IPropertyFactory.sol"
import "@devprotocol/protocol/contracts/interface/IAddressConfig.sol"
contract MyContract {
IAddressConfig public addressConfig;
constructor(address _addressConfig) public {
addressConfig = IAddressConfig(_addressConfig);
}
// This function mints and authenticate an ERC-20 tokens with hard-coded options, and returns the transaction fail/success.
function mint() external returns(bool) {
IPropertyFactory propertyFactory = IPropertyFactory(addressConfig.propertyFactory());
bool result = propertyFactory.createAndAuthenticate(
// Token name
"My Token",
// Token symbol
"MYT",
// Market address
"0xDbc05b1eCB4fdaEf943819C0B04e9ef6df4bAbd6",
// First argument to pass through to Market
"arg1",
// Second argument to pass through to Market
"arg2",
// Third argument to pass through to Market
"arg3"
);
return result;
}
}
See Ecosystem Addresses for AddressConfig contract addresses.