Overview
The TokenFactory module enables any account to create a new token with the following naming convention: factory/{creator address}/{subdenom}
. By namespace-separating tokens with the creator's address, token minting becomes permissionless, eliminating the need to resolve name collisions. A single account can create multiple denominations by providing a unique subdenom for each new denomination. Upon creation, the original creator is granted "admin" privileges over the asset. This allows them to:
Mint their denomination to any account
Burn their denomination from any account
Execute transfers of their denomination between any two accounts
Change the admin. In the future, additional admin capabilities may be introduced. Admins can opt to share admin privileges with other accounts using the authz module. The ChangeAdmin
functionality allows for changing the master admin account or even setting it to ""
, indicating that no account has admin privileges over the asset.
Tutorial
Create Denom
Creates a denom of factory/{creator address}/{subdenom}
with the given denom creator address and the subdenom. Subdenoms can consist of [a-zA-Z0-9./]
.
cli initia.js
Copy minitiad tx tokenfactory create-denom [sub-denom] \
--from test-account \
--gas auto --gas-adjustment 1.5 \
--gas-prices [gas-price] \
--node [rpc-url]:[rpc-port] \
--chain-id [chain-id]
Copy import {
LCDClient ,
MnemonicKey ,
MsgCreateDenom ,
Wallet ,
} from '@initia/initia.js' ;
async function main () {
const lcd = new LCDClient ( '[rest-url]' , {
gasPrices : '0.15uinit' ,
gasAdjustment : '1.5' ,
});
const key = new MnemonicKey ({
mnemonic : 'beauty sniff protect ...' ,
});
const wallet = new Wallet (lcd , key);
const msgs = [ new MsgCreateDenom ( key .accAddress , 'udenom' )];
// sign tx
const signedTx = await wallet .createAndSignTx ({ msgs });
// send(broadcast) tx
lcd . tx .broadcastSync (signedTx) .then (res => console .log (res));
// {
// height: 0,
// txhash: '0F2B255EE75FBA407267BB57A6FF3E3349522DA6DBB31C0356DB588CC3933F37',
// raw_log: '[]'
// }
}
main ();
Mint
Minting a specific denom is only allowed for the current admin. Note that the current admin defaults to the creator of the denom.
cli initia.js
Copy minitiad tx tokenfactory mint [amount] [to-address] \
--from test-account \
--gas auto --gas-adjustment 1.5 \
--gas-prices [gas-price] \
--node [rpc-url]:[rpc-port] \
--chain-id [chain-id]
# amount example
# 10000factory/init1.../udenom
Copy import {
Coin ,
LCDClient ,
MnemonicKey ,
MsgMint ,
Wallet ,
} from '@initia/initia.js' ;
async function main () {
const lcd = new LCDClient ( '[rest-url]' , {
gasPrices : '0.15uinit' ,
gasAdjustment : '1.5' ,
});
const key = new MnemonicKey ({
mnemonic : 'beauty sniff protect ...' ,
});
const wallet = new Wallet (lcd , key);
const msgs = [
new MsgMint (
key .accAddress ,
new Coin (
`factory/ ${ key .accAddress } /udenom` , // factory/creatoraddr/subdenom
1000
) ,
key .accAddress
) ,
];
// sign tx
const signedTx = await wallet .createAndSignTx ({ msgs });
// send(broadcast) tx
lcd . tx .broadcastSync (signedTx) .then (res => console .log (res));
// {
// height: 0,
// txhash: '0F2B255EE75FBA407267BB57A6FF3E3349522DA6DBB31C0356DB588CC3933F37',
// raw_log: '[]'
// }
}
main ();
Burn
Burning of a specific denom is only allowed for the current admin. Note that the current admin defaults to the creator of the denom.
cli initia.js
Copy minitiad tx tokenfactory burn [amount] [burn-from-address] \
--from test-account \
--gas auto --gas-adjustment 1.5 \
--gas-prices [gas-price] \
--node [rpc-url]:[rpc-port] \
--chain-id [chain-id]
# amount example
# 10000factory/init1.../udenom
Copy import {
Coin ,
LCDClient ,
MnemonicKey ,
MsgBurn ,
Wallet ,
} from '@initia/initia.js' ;
async function main () {
const lcd = new LCDClient ( '[rest-url]' , {
gasPrices : '0.15uinit' ,
gasAdjustment : '1.5' ,
});
const key = new MnemonicKey ({
mnemonic : 'beauty sniff protect ...' ,
});
const wallet = new Wallet (lcd , key);
const msgs = [
new MsgBurn (
key .accAddress ,
new Coin (
`factory/ ${ key .accAddress } /udenom` , // factory/creatoraddr/subdenom
1000
) ,
key .accAddress // burn from
) ,
];
// sign tx
const signedTx = await wallet .createAndSignTx ({ msgs });
// send(broadcast) tx
lcd . tx .broadcastSync (signedTx) .then (res => console .log (res));
// {
// height: 0,
// txhash: '0F2B255EE75FBA407267BB57A6FF3E3349522DA6DBB31C0356DB588CC3933F37',
// raw_log: '[]'
// }
}
main ();
ChangeAdmin
Change the admin of a denom. Note that this is only allowed to be called by the current admin of the denom.
cli initia.js
Copy minitiad tx tokenfactory change-admin [denom] [new-admin] \
--from test-account \
--gas auto --gas-adjustment 1.5 \
--gas-prices [gas-price] \
--node [rpc-url]:[rpc-port] \
--chain-id [chain-id]
# denom example
# factory/init1.../udenom
Copy import {
LCDClient ,
MnemonicKey ,
MsgChangeAdmin ,
Wallet ,
} from '@initia/initia.js' ;
async function main () {
const lcd = new LCDClient ( '[rest-url]' , {
gasPrices : '0.15uinit' ,
gasAdjustment : '1.5' ,
});
const key = new MnemonicKey ({
mnemonic : 'beauty sniff protect ...' ,
});
const wallet = new Wallet (lcd , key);
const msgs = [
new MsgChangeAdmin (
key .accAddress ,
`factory/ ${ key .accAddress } /udenom` , // factory/creatoraddr/subdenom
'init1...' // new admin
) ,
];
// sign tx
const signedTx = await wallet .createAndSignTx ({ msgs });
// send(broadcast) tx
lcd . tx .broadcastSync (signedTx) .then (res => console .log (res));
// {
// height: 0,
// txhash: '0F2B255EE75FBA407267BB57A6FF3E3349522DA6DBB31C0356DB588CC3933F37',
// raw_log: '[]'
// }
}
main ();
Last updated 6 months ago