I'm new to Aptos Move,
I'm writing a module to allow dynamic token as Solidity. In Solidity, we can pass the ERC20 address into the constructor, the smart contract will parse this address to an ERC20 smart contract and call transferFrom
function to transfer an amount
of token from sender
to this smart contract.
With a different architecture, according to my current knowledge, when constructing a module in Aptos Move, the owner still has to declare the type of token by function_name<address:token's module>(parameters)
. But the users calling functions related to the token have to include this function_name<address:token's module>(parameters)
too.
Summary: I'm wondering that in Solidity, users don't have to care too much about the blockchain, such as the address of the token, I just know that they have an amount of this token, so they can call some functions. However, in Aptos, users have to clearly declare what token they want to use.
Is the way I mention in Aptos Move when transferring tokens a standard and common way? Or did I misunderstand any part?
Thanks in advance for your guidance!
Yeah, that's correct. The approach in Aptos Move is intentionally more explicit than Solidity. When transferring tokens in Aptos Move, you need to specify the token type using generics like:
public entry fun deposit<CoinType>(amount: u64) {
// Transfer logic here
}`
This explicit type declaration is a core design choice in Move that provides additional safety and clarity. Solidity uses dynamic dispatch through addresses, but Move uses static typing to prevent runtime errors and make token interactions more predictable.
Users calling your module will indeed need to specify the token type:
module.deposit<0x1::aptos_coin::AptosCoin>(100)
This is the standard pattern across Aptos ecosystem and brings benefits like compile-time type checking and clearer code intentions. Hope it will be a clear understanding for you