The following code generates an error:
let account_id = env::signer_account_id();
let amount = 10 * 1_000_000_000_000_000_000_000_000;
Promise::new(account_id).transfer(amount);
env::log(format!("Sent {} NEAR to {}", amount, account_id).as_bytes());
|
102 | let account_id = env::signer_account_id();
| ---------- move occurs because `account_id` has type `std::string::String`, which does not implement the `Copy` trait
103 | let amount = 10 * 1_000_000_000_000_000_000_000_000;
104 | Promise::new(account_id).transfer(amount);
| ---------- value moved here
105 | env::log(format!("Sent {} NEAR to {}", amount, account_id).as_bytes());
| ^^^^^^^^^^ value borrowed here after move
I am able to work around this by declaring another variable same_account_id
which seems like a very bad way to get it to work.
let account_id = env::signer_account_id();
let same_account_id = env::signer_account_id();
let amount = 10 * 1_000_000_000_000_000_000_000_000;
Promise::new(account_id).transfer(amount);
env::log(format!("Sent {} NEAR to {}", amount, same_account_id).as_bytes());
What's a better/rusty way to reference account_id
after it has been passed as an argument in Promise::new()
?