Skip to content

Commit

Permalink
Add livenet payable example (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpob committed Apr 10, 2024
1 parent b19e647 commit 23bd1ba
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ path = "bin/erc20_on_livenet.rs"
required-features = ["livenet"]
test = false

[[bin]]
name = "tlw_on_livenet"
path = "bin/tlw_on_livenet.rs"
required-features = ["livenet"]
test = false

[[bin]]
name = "livenet_tests"
path = "bin/livenet_tests.rs"
Expand Down
30 changes: 30 additions & 0 deletions examples/bin/tlw_on_livenet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//! Deploys an [odra_examples::contracts::tlw::TimeLockWallet] contract, then deposits and withdraw some CSPRs.
use odra::casper_types::{AsymmetricType, PublicKey, U512};
use odra::host::{Deployer, HostRef};
use odra::Address;
use odra_examples::contracts::tlw::{TimeLockWalletHostRef, TimeLockWalletInitArgs};

const DEPOSIT: u64 = 100;
const WITHDRAWAL: u64 = 99;
const GAS: u64 = 20u64.pow(9);

fn main() {
let env = odra_casper_livenet_env::env();
let caller = env.get_account(0);

env.set_caller(caller);
env.set_gas(GAS);

let mut contract = TimeLockWalletHostRef::deploy(
&env,
TimeLockWalletInitArgs {
lock_duration: 60 * 60
}
);

contract.with_tokens(U512::from(DEPOSIT)).deposit();

println!("Owner's balance: {:?}", contract.get_balance(&caller));
contract.withdraw(&U512::from(WITHDRAWAL));
println!("Remaining balance: {:?}", contract.get_balance(&caller));
}

0 comments on commit 23bd1ba

Please sign in to comment.