Skip to content

Mikelle/go-safe-tx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-safe-tx

Go client for the Safe Transaction Service API. Propose transactions, batch via MultiSend, query pending txs.

Install

go get github.com/mikelle/go-safe-tx

Example

// signerKey is an *ecdsa.PrivateKey of a Safe owner/proposer.
// Parse from a hex string with crypto.HexToECDSA (without the 0x prefix):
signerKey, err := crypto.HexToECDSA("your_private_key_hex")

client, err := safetx.NewClient(
    big.NewInt(1),                                  // chain ID
    common.HexToAddress("0xYourSafe"),              // safe address
    signerKey,                                      // signer key
    "https://safe-transaction-mainnet.safe.global", // service URL
)

// single tx (returns safeTxHash)
hash, _ := client.ProposeTransaction(ctx, to, nil, calldata, safetx.Call)

// single tx with ETH value
hash, _ = client.ProposeTransaction(ctx, to, big.NewInt(1e18), nil, safetx.Call)

// batch
hash, _ = client.ProposeBatchTransaction(ctx, []safetx.BatchTransaction{
    {To: addr1, Data: data1},
    {To: addr2, Data: data2},
})

// nonce that accounts for queued txs
nonce, _ := client.NextNonce(ctx)

// check if a call is already pending
found, _ := client.HasPendingCall(ctx, selector, target)

Options

safetx.WithHTTPClient(customClient)
safetx.WithLogger(slog.Default())

Transaction Service URLs

Full list: https://docs.safe.global/advanced/api-supported-networks

Common ones:

  • Ethereum: https://safe-transaction-mainnet.safe.global
  • Arbitrum: https://safe-transaction-arbitrum.safe.global
  • Base: https://safe-transaction-base.safe.global
  • Optimism: https://safe-transaction-optimism.safe.global
  • Polygon: https://safe-transaction-polygon.safe.global

License

MIT

About

Go client for the Safe Transaction Service API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages