Go client for the Safe Transaction Service API. Propose transactions, batch via MultiSend, query pending txs.
go get github.com/mikelle/go-safe-tx// 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)safetx.WithHTTPClient(customClient)
safetx.WithLogger(slog.Default())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
MIT