Skip to Content
AutomationUsing --type-args in Automation

Using --type-args in Automation

When registering automation tasks for functions that use generic types, you must specify the concrete types using the --type-args parameter.

Working Example

Move Module: Auto Top-up with Generics

✅

Get Step by Step Guide to Setup Your First Automation Module HERE.


source.move
module exampleaddress::typearg { use supra_framework::coin; use supra_framework::supra_coin; use supra_framework::supra_coin::SupraCoin; public entry fun auto_topup<CoinType>( user: &signer, target: address, threshold: u64, amount: u64, ) { let target_balance = coin::balance<CoinType>(target); if (target_balance < threshold) { coin::transfer<CoinType>(user, target, amount); } } #[test(funder = @0xc1b2, target = @0xd3e4, supra_framework = @supra_framework)] fun test_auto_topup(funder: &signer, target: &signer, supra_framework: &signer) { let threshold = 100_000; let topup_amount = 1_000_000; let funder_addr = aptos_std::signer::address_of(funder); supra_framework::account::create_account_for_test(funder_addr); let (burn, mint) = supra_coin::initialize_for_test(supra_framework); coin::register<SupraCoin>(funder); supra_coin::mint(supra_framework, funder_addr, 100_000_000); // Mint 100M tokens to the funder let target_addr = aptos_std::signer::address_of(target); supra_framework::account::create_account_for_test(target_addr); coin::register<SupraCoin>(target); supra_coin::mint(supra_framework, target_addr, 1_000_000); let target_balance = coin::balance<SupraCoin>(target_addr); assert!(target_balance == 1_000_000, 1); // testcase as in if th target's balance is already above the threshold auto-topup should not trigger auto_topup<SupraCoin>(funder, target_addr, threshold, topup_amount); let target_balance = coin::balance<SupraCoin>(target_addr); assert!(target_balance == 1_000_000, 2); // Balance should remain unchanged // simulate transaction for target transfers tokens reducing balance below threshold coin::transfer<SupraCoin>(target, funder_addr, 950_000); let target_balance = coin::balance<SupraCoin>(target_addr); assert!(target_balance == 50_000, 3); // Balance drops below threshold // testcase now that the balance is below the threshold auto-topup should trigger auto_topup<SupraCoin>(funder, target_addr, threshold, topup_amount); let target_balance = coin::balance<SupraCoin>(target_addr); assert!(target_balance == 1_050_000, 4); // Balance should now include the top-up amount coin::destroy_burn_cap(burn); coin::destroy_mint_cap(mint); } }

Workflow

1. Deploy Your Contract

supra move tool publish \ --package-dir /path/to/your/project \ --rpc-url https://rpc-testnet.supra.com

2. Simulate Before Going Live

supra move automation register --simulate \ --task-max-gas-amount <MAX_GAS> \ --task-gas-price-cap <GAS_PRICE_CAP> \ --task-expiry-time-secs <EXPIRY> \ --task-automation-fee-cap <FEE_CAP> \ --function-id "<ADDRESS>::typearg::auto_topup" \ --type-args 0x1::supra_coin::SupraCoin \ --args address:<TARGET_ADDRESS> u64:<THRESHOLD> u64:<AMOUNT> \ --rpc-url https://rpc-testnet.supra.com

Derive <MAX_GAS>, <GAS_PRICE_CAP>, <EXPIRY> and <FEE_CAP> as described in Calculate task-expiry-time & task-automation-fee. <ADDRESS> is the address that published the module.

Use the correct Module Path for Specifying the --type-args:

✅ 0x1::supra_coin::SupraCoin

❌ supra_framework::supra_coin::SupraCoin

3. Automation Registration Command

Remove --simulate and run the same command
supra move automation register \ --task-max-gas-amount <MAX_GAS> \ --task-gas-price-cap <GAS_PRICE_CAP> \ --task-expiry-time-secs <EXPIRY> \ --task-automation-fee-cap <FEE_CAP> \ --function-id "<ADDRESS>::typearg::auto_topup" \ --type-args 0x1::supra_coin::SupraCoin \ --args address:<TARGET_ADDRESS> u64:600000000 u64:100000000 \ --rpc-url https://rpc-testnet.supra.com

Parameter Values

Amounts are in quants (1 SUPRA = 100,000,000 quants).

ParameterValueDescription
--task-max-gas-amount<MAX_GAS>Maximum gas for one execution of auto_topup
--task-gas-price-cap<GAS_PRICE_CAP>Highest gas unit price accepted; at or above max_gas_price from the RPC node
--task-expiry-time-secs<EXPIRY>start_time + duration_secs + buffer, from get_cycle_info
--task-automation-fee-cap<FEE_CAP>At or above the estimate_automation_fee result for <MAX_GAS>, in quants
--type-args0x1::supra_coin::SupraCoinConcrete type for generic
Target Address<TARGET_ADDRESS>Address to monitor
Threshold6000000006 SUPRA, in quants
Amount1000000001 SUPRA, in quants

Monitoring Your Automation on SupraScan

  • Visit SupraScan 
  • Enter your deployer address
  • Go to “Tasks” tab
  • Verify task is active

Using Type Args in Automation

Last updated on