Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

SingleSigner::sign_transaction

Sign a set of messages and produce a broadcast-ready Tx.

Signature

impl<S: Secret> Signer for SingleSigner<S> {
    fn sign_transaction(
        &mut self,
        msgs: NonEmpty<Vec<Message>>,
        chain_id: &str,
        gas_limit: u64,
    ) -> grug::StdResult<grug::Tx>;
}

From impl Signer (requires Defined<UserIndex> + Defined<Nonce>).

Example

use {
    anyhow::Result,
    dango_sdk::{HttpClient, SingleSigner},
    grug::{BroadcastClient, Coins, Message, NonEmpty, Signer},
};
 
async fn submit(
    http: &HttpClient,
    signer: &mut SingleSigner<impl dango_sdk::Secret>,
) -> Result<()> {
    let messages = NonEmpty::new(vec![
        Message::transfer(grug::Addr::mock(1), Coins::one("bridge/usdc", 100_u128)?)?,
    ])?;
    let tx = signer.sign_transaction(messages, "dango-1", 1_000_000)?;
    let _  = http.broadcast_tx(tx).await?;
    Ok(())
}

Parameters

msgsNonEmpty<Vec<Message>>. The messages to include.

chain_id&str. Target chain id.

gas_limitu64. Maximum gas the transaction is allowed to consume.

Returns

Txsender, msgs, gas_limit, JSON-encoded metadata, and a JSON-encoded Credential::Standard { key_hash, signature }.

Notes

  • Side effect: *self.nonce.inner_mut() += 1. The in-memory nonce is advanced even though the method takes &mut self. Successive calls produce successive transactions without re-querying.
  • On broadcast failure, the in-memory nonce is now ahead of the chain. Call SequencedSigner::update_nonce (or query_next_nonce + with_nonce) to resync.
  • Eip712 signatures are EIP-712 typed-data with domain { name: "dango", chain_id: EIP155_CHAIN_ID, verifying_contract: <sender as U160> }.
  • Errors are StdError from JSON encoding or the Secret::sign_transaction call.

See also