How to create multiple coins? #122
-
Asked by
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 17 replies
-
|
Beta Was this translation helpful? Give feedback.
-
Calling @gregnazario for help, when i run the unit test in below, it triggers
The only way initialize can work is I call it with deployer account and pass deployer signer. I don't understand why we have this restriction, how do we support apps like launchpad where we need one contract as the entry point for people to create coin? module playgrouund_addr::coin_playground {
use std::string;
use aptos_framework::account;
use aptos_framework::coin;
struct TestCoin has key {}
struct CoinCap has key {
mint_capability: coin::MintCapability<TestCoin>,
burn_capability: coin::BurnCapability<TestCoin>,
freeze_capability: coin::FreezeCapability<TestCoin>,
}
public entry fun create_coin(sender: &signer) {
let (resource_signer, _signer_cap) = account::create_resource_account(sender, b"token_account");
let (burn_cap, freeze_cap, mint_cap) = coin::initialize<TestCoin>(
&resource_signer,
string::utf8(b"Test"),
string::utf8(b"symbol"),
8,
true
);
move_to(
&resource_signer,
CoinCap {
burn_capability: burn_cap,
freeze_capability: freeze_cap,
mint_capability: mint_cap
}
);
}
#[test(sender = @playgrouund_addr, user1 = @0x100, user2 = @0x101)]
fun test_happy_path(sender: &signer, user1: &signer, user2: &signer) {
// this will trigger ECOIN_INFO_ADDRESS_MISMATCH in 0x1::coin
create_coin(sender);
}
} |
Beta Was this translation helpful? Give feedback.
Only the publisher of the struct can create a coin with that struct, and they can only do so once.
To create multiple coins, deploy more structs and use the publisher's account to create the coins