script { use std::signer; use aptos_framework::aptos_account; use aptos_framework::aptos_coin; use aptos_framework::coin; fun main(src: &signer, dest: address, desired_balance: u64) { let src_addr = signer::address_of(src); addr::my_module::do_nothing(); let balance = coin::balance<aptos_coin::AptosCoin>(src_addr); if (balance < desired_balance) { aptos_account::transfer(src, dest, desired_balance - balance); }; }}
script { use std::signer; use aptos_framework::aptos_account; use aptos_framework::aptos_coin; use aptos_framework::coin; fun main(src: &signer, dest: address, desired_balance: u64) { let src_addr = signer::address_of(src); addr::my_module::do_nothing(); let balance = coin::balance<aptos_coin::AptosCoin>(src_addr); if (balance < desired_balance) { aptos_account::transfer(src, dest, desired_balance - balance); }; }}
sources/my_module.move
module addr::my_module {
public entry fun do_nothing() { }
}
Compiling, may take a little while to download git dependencies...UPDATING GIT DEPENDENCY https://github.com/aptos-labs/aptos-core.gitINCLUDING DEPENDENCY AptosFrameworkINCLUDING DEPENDENCY AptosStdlibINCLUDING DEPENDENCY MoveStdlibBUILDING run_script{ "Result": [ "754c1acc2425a06cf70076268f9fb087504c96393e6a3615595402fc1e11d713::my_module" ]}
Compiling, may take a little while to download git dependencies...UPDATING GIT DEPENDENCY https://github.com/aptos-labs/aptos-core.gitINCLUDING DEPENDENCY AptosFrameworkINCLUDING DEPENDENCY AptosStdlibINCLUDING DEPENDENCY MoveStdlibBUILDING run_scriptpackage size 728 bytesDo you want to submit a transaction for a range of [12450 - 18600] Octas at a gas unit price of 150 Octas? [yes/no] >$ yes # 你需要在这里输入 yes 或者 y{ "Result": { "transaction_hash": "0x9a2a058affc3237bd5d427a7d45209d0a95ccf019467083b89dc11f5dd1942d8", "gas_used": 83, "gas_unit_price": 150, "sender": "754c1acc2425a06cf70076268f9fb087504c96393e6a3615595402fc1e11d713", "sequence_number": 2, "success": true, "timestamp_us": 1720006799741145, "version": 3150901501, "vm_status": "Executed successfully" }}
NOTE
一定要发布这个模块到链上,否则会出现模块不存在的错误:
{ "Error": "Simulation failed with status: LINKER_ERROR\nExecution failed with message: Linker Error: Module 754c1acc2425a06cf70076268f9fb087504c96393e6a3615595402fc1e11d713::my_module doesn't exist"}
Do you want to submit a transaction for a range of [1200 - 1800] Octas at a gas unit price of 100 Octas? [yes/no] >$ yes # 你需要在这里输入 yes 或者 y{ "Result": { "transaction_hash": "0x916c88e5b41347ce5e2dba462afda544ef77ed602a715a2b3301a550740b2024", "gas_used": 8, "gas_unit_price": 150, "sender": "754c1acc2425a06cf70076268f9fb087504c96393e6a3615595402fc1e11d713", "sequence_number": 1, "success": true, "timestamp_us": 1720006544105831, "version": 3149726659, "vm_status": "Executed successfully" }}