Documentation Index
Fetch the complete documentation index at: https://injectivelabs-mintlify-jp-native-developers-first-half.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
tokenfactoryモジュールにより、任意のアカウントがfactory/{creator address}/{subdenom}という名前で新しいトークンを作成できます。トークンが作成者アドレスでnamespace化されるため、名前の衝突を解決する必要がなく、トークンのミントをパーミッションレスで行えます。
注: Helix、Hub、Explorerなどのプロダクトでdenomを表示したい場合は、下記の説明にあるようにMsgSetDenomMetadataメッセージを使用してトークンのメタデータ情報を追加することが重要です。
注 #2: 安全性のため、また供給量の操作を防止するため、adminをzero addressに変更することを推奨します。
メッセージ
TokenFactoryモジュールがエクスポートし、Injectiveチェーンとのやり取りに使用できるメッセージを順番に確認し、例を提供します。
MsgCreateDenom
denom作成者アドレスとsubdenomを指定してfactory/{creator address}/{subdenom}のdenomを作成します。Subdenomには[a-zA-Z0-9./]を含めることができます。新しいトークンを作成する際にカバーする必要があるcreation feeがあることに注意してください。
トークンのadminは供給量を変更できる(新しいトークンをミントまたはバーンできる)ことに注意してください。下記の説明にあるように、MsgChangeAdminを使用してadminを解除(unset)することを推奨します。
import { Network } from "@injectivelabs/networks";
import { MsgCreateDenom } from "@injectivelabs/sdk-ts/core/modules";
import { MsgBroadcasterWithPk } from "@injectivelabs/sdk-ts/core/tx";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
const subdenom = "inj-test";
const msg = MsgCreateDenom.fromJSON({
subdenom,
symbol: "InjTest",
name: "Inj Testing",
sender: injectiveAddress,
});
const txHash = await new MsgBroadcasterWithPk({
privateKey,
network: Network.Testnet,
}).broadcast({
msgs: msg,
});
console.log(txHash);
MsgMint
特定のdenomのミントは現在のadminのみが許可されます。なお、現在のadminはデフォルトでdenomの作成者になります。
import { Network } from "@injectivelabs/networks";
import { MsgMint } from "@injectivelabs/sdk-ts/core/modules";
import { MsgBroadcasterWithPk } from "@injectivelabs/sdk-ts/core/tx";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
const subdenom = "inj-test";
const amountToMint = 1_000_000_000;
const msg = MsgMint.fromJSON({
sender: injectiveAddress,
amount: {
denom: `factory/${injectiveAddress}/${subdenom}`,
amount: amountToMint,
},
});
const txHash = await new MsgBroadcasterWithPk({
privateKey,
network: Network.Testnet,
}).broadcast({
msgs: msg,
});
console.log(txHash);
MsgBurn
adminはtoken factoryの供給量をバーンできます。それ以外のすべての人は、このメッセージを使用して自分の資金のみをバーンできます。
import { Network } from "@injectivelabs/networks";
import { MsgBurn } from "@injectivelabs/sdk-ts/core/modules";
import { MsgBroadcasterWithPk } from "@injectivelabs/sdk-ts/core/tx";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
const subdenom = "inj-test";
const amountToBurn = 1_000_000_000;
const msg = MsgBurn.fromJSON({
sender: injectiveAddress,
amount: {
denom: `factory/${injectiveAddress}/${subdenom}`,
amount: amountToBurn,
},
});
const txHash = await new MsgBroadcasterWithPk({
privateKey,
network: Network.Testnet,
}).broadcast({
msgs: msg,
});
console.log(txHash);
特定のdenomへのメタデータの設定はdenomのadminのみが許可されます。bankモジュール内のdenomメタデータを上書きできます。
import { Network } from "@injectivelabs/networks";
import { MsgSetDenomMetadata } from "@injectivelabs/sdk-ts/core/modules";
import { MsgBroadcasterWithPk } from "@injectivelabs/sdk-ts/core/tx";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
const subdenom = 'inj-test'
const denom = `factory/${injectiveAddress}/${subdenom}`;
const denomUnitsIfTokenHas0Decimals = [
{
denom: denom,
exponent: 0,
aliases: [subdenom]
},
]
const denomUnitsIfTokenHas6Decimals = [
{
denom: denom, /** we use the whole denom here */
exponent: 0,
aliases: [subdenom]
},
{
denom: subdenom,
exponent: 6, /** we use the subdenom only here (if you want your token to have 6 decimals) */
aliases: []
},
]
const msg = MsgSetDenomMetadata.fromJSON({
sender: injectiveAddress,
metadata: {
base: denom, /** the base denom */
description: '', /** description of your token */
display: subdenom, /** the display alias of your token on UIs (it's the denom of the unit with highest decimals) */
name: '', /** the name of your token */
symbol: '', /** the symbol of your token */
uri: '' /** the logo of your token, should be hosted on IPFS and should be a small webp image */
denomUnits: denomUnitsIfTokenHas6Decimals /** choose if you want to have 6 or 0 decimals for the token */,
decimals: 6 /** choose if you want to have 6 or 0 decimals for the token */
}
});
const txHash = await new MsgBroadcasterWithPk({
privateKey,
network: Network.Testnet
}).broadcast({
msgs: msg
});
console.log(txHash);
MsgChangeAdmin
denomのadminは新しい供給量をミントしたり、既存のものをバーンしたりできます。トークンの供給量変更を許可しないように、adminをzero addressに変更することを推奨します。
import { Network } from "@injectivelabs/networks";
import { MsgChangeAdmin } from "@injectivelabs/sdk-ts/core/modules";
import { MsgBroadcasterWithPk } from "@injectivelabs/sdk-ts/core/tx";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
const subdenom = "inj-test";
const denom = `factory/${injectiveAddress}/${subdenom}`;
const msg = MsgChangeAdmin.fromJSON({
denom,
sender: injectiveAddress,
newAdmin:
"inj1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqe2hm49" /** SET TO ZERO ADDRESS */,
});
const txHash = await new MsgBroadcasterWithPk({
privateKey,
network: Network.Testnet,
}).broadcast({
msgs: msg,
});
console.log(txHash);
完全な例
Injective上で新しいトークンを作成し、新しいトークンをミントし、トークンメタデータを設定する完全な例は次のとおりです。
import { Network } from "@injectivelabs/networks";
import { MsgBroadcasterWithPk } from "@injectivelabs/sdk-ts/core/tx";
import { MsgSetDenomMetadata, MsgCreateDenom, MsgMint, MsgChangeAdmin } from "@injectivelabs/sdk-ts/core/modules";
const injectiveAddress = "inj1...";
const privateKey = "0x...";
const subdenom = 'inj-test'
const denom = `factory/${injectiveAddress}/${subdenom}`;
const amount = 1_000_000_000
const msgCreateDenom = MsgCreateDenom.fromJSON({
subdenom,
sender: injectiveAddress,
});
const msgMint = MsgMint.fromJSON({
sender: injectiveAddress,
amount: {
denom: `factory/${injectiveAddress}/${subdenom}`,
amount: amount
}
});
const msgChangeAdmin = MsgChangeAdmin.fromJSON({
denom: `factory/${injectiveAddress}/${subdenom}`,
sender: injectiveAddress,
newAdmin: 'inj1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqe2hm49' /** SET TO ZERO ADDRESS */
});
const msgSetDenomMetadata = MsgSetDenomMetadata.fromJSON({
sender: injectiveAddress,
metadata: {
base: denom, /** the base denom */
description: '', /** description of your token */
display: '', /** the displayed name of your token on UIs */,
name: '', /** the name of your token */,
symbol: '' /** the symbol of your token */,
uri: '' /** the logo of your token, should be hosted on IPFS and should be a small webp image */
denomUnits: [
{
denom: denom,
exponent: 0,
aliases: [subdenom]
},
{
denom: subdenom,
exponent: 6, /** if you want your token to have 6 decimals */
aliases: []
},
]
}
});
const txHash = await new MsgBroadcasterWithPk({
privateKey,
network: Network.Testnet
}).broadcast({
msgs: [msgCreateDenom, msgMint, msgSetDenomMetadata, msgChangeAdmin]
});
console.log(txHash);