- BETH
- Guides
- Transfer and receive BETH
Transfer and receive BETH
BETH overview · BETH environments and prerequisites · Transfer and receive BETH
Outcome
Section titled “Outcome”Send BETH from one Canton party to another, read the result of the transfer, and accept, reject, or cancel a transfer offer.
Before you start
Section titled “Before you start”- Use an Engineering-approved
bitsafe-token-lib,canton-lib, DAR, and Canton compatibility row. This guide describesbitsafe-token-libv0.6.0. - Confirm authentication, the sender party, the receiver party, and the registry URL for the intended environment.
- Confirm the BETH instrument identifier. The identifier is the instrument ID
BETHand the administrator party. The library matches both values exactly. - Query the sender’s holdings, and confirm that the sender has enough available BETH.
How a transfer settles
Section titled “How a transfer settles”A transfer has one of two outcomes:
- Offer: the registry creates a transfer instruction. The receiver accepts or rejects it, or it expires at
execute_before. The sender can cancel it before the receiver acts. - Settled on submission: the registry moves the BETH at once, and no offer exists. The registry does this for a self-transfer and for a receiver that pre-approved the sender.
The library tells you which outcome occurred. Do not assume that the receiver must accept.
1. Send BETH
Section titled “1. Send BETH”Call bitsafe_token::transfer::submit as the sender. The call returns a TransferReceipt.
let now = jiff::Timestamp::now();let receipt = bitsafe_token::transfer::submit(bitsafe_token::transfer::Params { transfer: bitsafe_token::Transfer { sender: sender_party.clone(), receiver: receiver_party.clone(), amount: bitsafe_token::DamlDecimal::parse("0.01")?, instrument_id: bitsafe_token::InstrumentId { admin: decentralized_party_id.clone(), id: bitsafe_token::tokens::beth::TICKER.to_string(), }, requested_at: now.to_string(), execute_before: (now + jiff::SignedDuration::from_hours(168)).to_string(), input_holding_cids: None, // None lets the library select the sender's holdings meta: None, }, ledger_host: ledger_host.clone(), access_token: sender_token.clone(), registry_url: registry_url.clone(), decentralized_party_id: decentralized_party_id.clone(),}).await?;The sample uses the jiff crate for the two times. Add jiff = "1" to your dependencies.
Run the repository example with ASSET=beth cargo run --example send.
2. Read the transfer receipt
Section titled “2. Read the transfer receipt”The receipt contains three fields:
| Field | Meaning |
|---|---|
outcome | TransferOutcome::Pending for an offer, or TransferOutcome::Completed for a settled transfer. |
sender_change_cids | The sender holdings that remain after the transfer. |
update_id | The Canton update identifier of the transaction. |
receipt.outcome.transfer_offer_cid() returns the offer contract ID for a pending transfer. It returns None for a settled transfer. Record the offer ID, because the receiver and the sender need it in the next steps.
3. Receive BETH
Section titled “3. Receive BETH”Skip this step when the outcome is Completed. The receiver already holds the BETH.
For a pending transfer, the receiver authenticates as the receiver party and does one of these actions:
- Accept one offer: call
bitsafe_token::accept::submitwith the offer contract ID and the receiver party. - Accept all offers: call
bitsafe_token::accept::accept_all. It returns one result for each offer and the successful and failed counts. Readfailed_countbefore you treat the step as done. - Reject an offer: call
bitsafe_token::reject::submitwith the offer contract ID and the receiver party. The BETH returns to the sender.
To list the receiver’s pending offers, run ASSET=beth cargo run --example list_incoming_offers.
4. Cancel an outgoing offer
Section titled “4. Cancel an outgoing offer”The sender can withdraw an offer that the receiver has not accepted or rejected:
bitsafe_token::cancel_offers::submitwithdraws one offer.bitsafe_token::cancel_offers::withdraw_batchwithdraws a list of offers.bitsafe_token::cancel_offers::withdraw_allwithdraws all pending offers of the instrument.
To list the sender’s pending offers, run ASSET=beth cargo run --example list_outgoing_offers. To withdraw them, run ASSET=beth cargo run --example cancel_offers.
Token Standard V2
Section titled “Token Standard V2”Each operation in this guide also has a Token Standard V2 form in a v2 submodule, such as bitsafe_token::transfer::v2::submit. The V2 transfer takes the sender and the receiver as bitsafe_token::Account values instead of party strings. The accept, reject, and cancel V2 forms take the same parameters as V1.
Run the V2 transfer example with ASSET=beth cargo run --example send_v2.
Expected result
Section titled “Expected result”- The sender has a
TransferReceiptand a recorded outcome for each transfer. - For a settled transfer, the receiver holds the BETH.
- For an offer, the receiver accepted or rejected it, the sender cancelled it, or it expired.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Check |
|---|---|
| The receiver sees no offer. | Read the sender’s receipt. A Completed outcome creates no offer, and the receiver already holds the BETH. |
| The receiver’s balance does not change. | Confirm the instrument ID and the administrator. The library ignores holdings of another administrator. |
| Accept or reject fails. | Confirm that the token authenticates the receiver party and that the offer is still active. |
| The transfer fails with insufficient funds. | Query the sender’s holdings. Holdings locked in another offer are not available. |
Technical sources
Section titled “Technical sources”bitsafe-token-libREADME atv0.6.0- Transfer implementation and receipt model
- Accept implementation
- Reject implementation
- Cancel implementation
- Send example
- Reject example
Related pages
Section titled “Related pages”Next step
Section titled “Next step”Send to many receivers: Batch transfers and UTXO management.
Ask the docs
Answers come only from this documentation and can be wrong. Check the linked pages.
Ask a question about BitSafe, CBTC or the developer guides. For example: