```rust
async fn main(){ let mut client = vitabotapi::Client::new("Your api key from vitamin.tips".tostring());
let token1 = client.get_token("VITC".to_string()).await.unwrap();
let token2 = client.get_token("VITC-000".to_string()).await.unwrap();
let token3 = client.get_token("BAN-001".to_string()).await.unwrap();
let amount1 = client.parse_amount("1 vitc".to_string()).await.unwrap();
let amount2 = client.parse_amount("$10 vitc".to_string()).await.unwrap();
let amount2 = client.parse_amount("129k VITE".to_string()).await.unwrap();
// in a discord bot
let recipient = client.get_discord_user_address("696481194443014174".to_string()).await.unwrap(); // 696481194443014174 is your user id
let user_id = client.resolve_discord_user_from_address(recipient.clone()).await.unwrap();
let addresses = client.get_addresses().await.unwrap();
let balances = client.get_balances().await.unwrap();
let balance1 = client.get_balance(vitabot_api::BankAccount::Index(0)).await.unwrap();
let balance2 = client.get_balance(vitabot_api::BankAccount::Address("vite_xxxxxx".to_string())).await.unwrap();
let address = client.new_address().await.unwrap();
let transaction = client.send_transaction(vitabot_api::TransactionRequest {
from: vitabot_api::BankAccount::Index(0),
to: recipient,
amount: amount1.amount,
token_id: amount1.token_id,
data: vec![] // empty data field
});
} ```
This example was extended from the Serenity Example Bot. ```rust use std::env;
use serenity::async_trait; use serenity::prelude::*; use serenity::model::channel::Message; use serenity::framework::standard::macros::{command, group}; use serenity::framework::standard::{StandardFramework, CommandResult};
extern crate lazy_static;
struct General;
struct Handler;
impl EventHandler for Handler {}
lazystatic! { static ref VITABOT:vitabotapi::Client = { let key = env::var("VITABOTKEY").expect("VITABOTKEY"); vitabot_api::Client::new(key) }; }
async fn main() { let framework = StandardFramework::new() .configure(|c| c.prefix("!")) // set the bot's prefix to "!" .group(&GENERAL_GROUP);
// Login with a bot token from the environment
let token = env::var("DISCORD_TOKEN").expect("token");
let intents = GatewayIntents::non_privileged() | GatewayIntents::MESSAGE_CONTENT;
let mut client = Client::builder(token, intents)
.event_handler(Handler)
.framework(framework)
.await
.expect("Error creating client");
// start listening for events by starting a single shard
if let Err(why) = client.start().await {
println!("An error occurred while running the client: {:?}", why);
}
}
async fn faucet(ctx: &Context, msg: &Message) -> CommandResult { let amount = VITABOT.parseamount("1 vitc".tostring()).await.unwrap(); let addresses = VITABOT.getaddresses().await.unwrap(); let recipient = VITABOT.getdiscorduseraddress(msg.author.id.0.tostring()).await.unwrap(); let transaction = VITABOT.sendtransaction(vitabotapi::TransactionRequest { from: vitabotapi::BankAccount::Address(addresses[0].address.clone()), to: recipient, amount: amount.amount, tokenid: amount.tokenid, data: vec![] }).await.unwrap();
msg.reply_ping(&ctx.http, format!("https://vitcscan.com/tx/{}", transaction.hash)).await?;
Ok(())
} ```