diff --git a/integration/rust.md b/integration/rust.md index 05eac3a..de26bce 100644 --- a/integration/rust.md +++ b/integration/rust.md @@ -33,15 +33,47 @@ The `Cargo.toml` file is a standard file for Rust projects. Now, we can use the generated bindings to build a transaction using our protocol. First access to the `gen/rust` folder + ```bash cd gen/rust ``` -We need to open `lib.rs` and update the TRP endpoint to point to the correct URL (unless you have it configured on trix.toml). The default value is `http://localhost:3000/trp`, but if you're using different port or endpoint, make sure to update it. +We need to open `lib.rs` and update the TRP endpoint to point to the correct URL (unless you have it configured in `trix.toml`). For the local devnet the TRP endpoint is available at `http://localhost:8164/`. If you're using a different port or network, update this value accordingly or set it in `trix.toml`. For the following example, we will use the main.tx3 file generated by trix. -Now, we can create a new file called `src/bin/test.rs` in the same folder (or any other folder) and add the following code: +Before running the example below, start the local devnet in a separate terminal with: + +``` +trix devnet +``` + +The devnet will start and print timestamped INFO logs that show the Devnet components starting, running, and stopping. +While the emulator is starting you should see startup messages and the tool prints sample wallets and addresses. + +If you don’t see addresses in the console or if you need to look up the addresses for a specific named wallet (for example a wallet defined in `trix.toml`), you can run: + +```bash +trix wallet +# e.g. trix wallet alice +``` + +This command returns a small JSON structure that includes the `testnet` address you should use in examples. Example output: + +```json +{ + "name": "alice", + "public_key": "9b1622919b3a74c037599d67d065f10c46c047801efe024a80344e79be4d9c0b2edb662977726943b63e8c9c5ee761c77f682ee31ef28e74fcab8a54bf692438", + "addresses": { + "testnet": "addr_test1vqn7k6gfllvhauxkzw478ds2f9axmu4qw78pm86dtyd40yqg2w3rq", + "mainnet": "addr1vyn7k6gfllvhauxkzw478ds2f9axmu4qw78pm86dtyd40yqnz6dv9" + } +} +``` + +Use the `testnet` address value as the sender/receiver address in the Rust example. + +Now, create a new file called `src/bin/test.rs` inside the generated crate (for example: `gen/rust/src/bin/test.rs`) so that Cargo can find and run it. Add the following code (replace the placeholder addresses with the ones obtained via `trix wallet`): ```rust use tx3_sdk::trp::args::ArgValue; @@ -49,9 +81,9 @@ use tx3_sdk::trp::args::ArgValue; #[tokio::main] async fn main() { let params = trix_example::TransferParams { - sender: ArgValue::from("addr_test1vpgcjapuwl7gfnzhzg6svtj0ph3gxu8kyuadudmf0kzsksqrfugfc"), - receiver: ArgValue::from("addr_test1vpry6n9s987fpnmjqcqt9un35t2rx5t66v4x06k9awdm5hqpma4pp"), - quantity: ArgValue::from(100000000), + sender: ArgValue::from("addr_test1vqn7k6gfllvhauxkzw478ds2f9axmu4qw78pm86dtyd40yqg2w3rq"), + receiver: ArgValue::from("addr_test1vqxazu4ekxrxlk238wt0e03h3gk44hrlkjvef85gvh2nahcgnmpfc"), + quantity: ArgValue::Int(100000000), }; match trix_example::PROTOCOL.transfer_tx(params).await { @@ -64,17 +96,21 @@ async fn main() { } } ``` + **NOTE**: Replace `trix_example` with the name of your protocol. To your Cargo.toml file, add the following dependencies: + ```toml tokio = { version = "1", features = ["full"] } ``` Finally, we can run the test file to build a transaction using our protocol: + ```bash cargo run --bin test ``` + If everything went well, you should see a message like this: ```bash