-
Notifications
You must be signed in to change notification settings - Fork 3
/
erc20_on_livenet.rs
51 lines (40 loc) · 1.52 KB
/
erc20_on_livenet.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use odra::casper_types::U256;
use odra::host::{Deployer, HostEnv, HostRef, HostRefLoader};
use odra::Address;
use odra_modules::erc20::{Erc20HostRef, Erc20InitArgs};
use std::str::FromStr;
fn main() {
let env = odra_casper_livenet_env::env();
let owner = env.caller();
let recipient = "hash-2c4a6ce0da5d175e9638ec0830e01dd6cf5f4b1fbb0724f7d2d9de12b1e0f840";
let recipient = Address::from_str(recipient).unwrap();
// Deploy new contract.
let mut token = deploy_erc20(&env);
println!("Token address: {}", token.address().to_string());
// Uncomment to load existing contract.
// let mut token = load_erc20(&env);
println!("Token name: {}", token.name());
env.set_gas(3_000_000_000u64);
token.transfer(recipient, U256::from(1000));
println!("Owner's balance: {:?}", token.balance_of(owner));
println!("Recipient's balance: {:?}", token.balance_of(recipient));
}
fn _load_erc20(env: &HostEnv) -> Erc20HostRef {
let address = "hash-d26fcbd2106e37be975d2045c580334a6d7b9d0a241c2358a4db970dfd516945";
let address = Address::from_str(address).unwrap();
Erc20HostRef::load(env, address)
}
pub fn deploy_erc20(env: &HostEnv) -> Erc20HostRef {
let name = String::from("Plascoin");
let symbol = String::from("PLS");
let decimals = 10u8;
let initial_supply = Some(U256::from(10_000));
let init_args = Erc20InitArgs {
name,
symbol,
decimals,
initial_supply
};
env.set_gas(100_000_000_000u64);
Erc20HostRef::deploy(env, init_args)
}