From 63d6a0f1a3a712d56f4aa4a88ae265b015b187b8 Mon Sep 17 00:00:00 2001 From: Brendan Ryan Date: Tue, 3 Feb 2026 17:03:22 -0800 Subject: [PATCH 1/4] add more examples to go docs --- src/pages/sdk/go/index.mdx | 230 ++++++++++++++++++++++++++++--------- 1 file changed, 177 insertions(+), 53 deletions(-) diff --git a/src/pages/sdk/go/index.mdx b/src/pages/sdk/go/index.mdx index f54e3b8f..3dbdb2ec 100644 --- a/src/pages/sdk/go/index.mdx +++ b/src/pages/sdk/go/index.mdx @@ -31,21 +31,29 @@ To interact with Tempo, first create an RPC client connected to a Tempo node: package main import ( + "context" "fmt" "github.com/tempoxyz/tempo-go/pkg/client" ) func main() { - c, err := client.New("https://rpc.moderato.tempo.xyz") // [!code focus] - if err != nil { // [!code focus] - panic(err) // [!code focus] - } // [!code focus] + c := client.New("https://rpc.testnet.tempo.xyz") // [!code focus] - fmt.Println("Connected to Tempo") + ctx := context.Background() + blockNum, _ := c.GetBlockNumber(ctx) // [!code focus] + fmt.Printf("Connected to Tempo at block %d\n", blockNum) // [!code focus] } ``` +For authenticated RPC endpoints: + +```go [main.go] +c := client.New("https://rpc.testnet.tempo.xyz", + client.WithAuth("username", "password"), +) +``` + ## Create a Signer Create a signer to sign transactions. The signer manages your private key and generates signatures: @@ -56,13 +64,10 @@ package main import ( "fmt" - "github.com/tempoxyz/tempo-go/pkg/client" - "github.com/tempoxyz/tempo-go/pkg/signer" // [!code focus] + "github.com/tempoxyz/tempo-go/pkg/signer" ) func main() { - c, _ := client.New("https://rpc.moderato.tempo.xyz") - s, err := signer.NewSigner("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80") // [!code focus] if err != nil { // [!code focus] panic(err) // [!code focus] @@ -74,13 +79,14 @@ func main() { ## Send a Transaction -Now we can build and send a transaction. Tempo transactions support batching multiple calls in a single transaction: +Build and send a transaction using the builder pattern: ```go [main.go] package main import ( - "fmt" + "context" + "log" "math/big" "github.com/ethereum/go-ethereum/common" @@ -90,71 +96,170 @@ import ( ) func main() { - c, _ := client.New("https://rpc.moderato.tempo.xyz") + c := client.New("https://rpc.testnet.tempo.xyz") s, _ := signer.NewSigner("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80") + ctx := context.Background() + nonce, _ := c.GetTransactionCount(ctx, s.Address().Hex()) // [!code focus] + recipient := common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8") - amount := new(big.Int).Mul(big.NewInt(10), big.NewInt(1e18)) - transferData := buildERC20TransferData(recipient, amount) - - // [!code focus:13] - tx := transaction.New() - tx.ChainID = big.NewInt(42431) // Tempo testnet - tx.MaxFeePerGas = big.NewInt(2000000000) - tx.MaxPriorityFeePerGas = big.NewInt(1000000000) - tx.Gas = 100000 - tx.Calls = []transaction.Call{{ - To: &transaction.AlphaUSDAddress, - Value: big.NewInt(0), - Data: transferData, - }} + + // [!code focus:10] + tx := transaction.NewBuilder(big.NewInt(42429)). // Tempo testnet + SetNonce(nonce). + SetGas(100000). + SetMaxFeePerGas(big.NewInt(10000000000)). + SetMaxPriorityFeePerGas(big.NewInt(1000000000)). + AddCall(recipient, big.NewInt(0), []byte{}). + Build() transaction.SignTransaction(tx, s) - hash, _ := c.SendTransaction(tx) - fmt.Printf("Transaction hash: %s\n", hash.Hex()) + serialized, _ := transaction.Serialize(tx, nil) + hash, _ := c.SendRawTransaction(ctx, serialized) // [!code focus] + log.Printf("Transaction hash: %s", hash) } +``` + +:::: + +## Examples + +### Read Chain Data + +Query the blockchain for basic information: + +```go [read.go] +ctx := context.Background() + +blockNum, _ := c.GetBlockNumber(ctx) +chainID, _ := c.GetChainID(ctx) +nonce, _ := c.GetTransactionCount(ctx, "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb") + +fmt.Printf("Block: %d, Chain: %d, Nonce: %d\n", blockNum, chainID, nonce) +``` -func buildERC20TransferData(to common.Address, amount *big.Int) []byte { +### Token Transfer + +Send a TIP-20 token transfer using ABI-encoded calldata: + +```go [transfer.go] +recipient := common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8") +amount := big.NewInt(100_000_000) // 100 tokens (6 decimals) + +transferData := encodeTransfer(recipient, amount) + +tx := transaction.NewBuilder(big.NewInt(42429)). + SetNonce(nonce). + SetGas(100000). + SetMaxFeePerGas(big.NewInt(10000000000)). + SetMaxPriorityFeePerGas(big.NewInt(1000000000)). + AddCall(transaction.AlphaUSDAddress, big.NewInt(0), transferData). + Build() + +func encodeTransfer(to common.Address, amount *big.Int) []byte { data := make([]byte, 68) - data[0], data[1], data[2], data[3] = 0xa9, 0x05, 0x9c, 0xbb + copy(data[0:4], []byte{0xa9, 0x05, 0x9c, 0xbb}) // transfer(address,uint256) copy(data[16:36], to.Bytes()) amount.FillBytes(data[36:68]) return data } ``` -:::: +### Transfer with Memo -## Examples +Include a memo for payment reconciliation: + +```go [memo.go] +recipient := common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8") +amount := big.NewInt(100_000_000) +memo := [32]byte{} +copy(memo[:], "INV-12345") + +memoData := encodeTransferWithMemo(recipient, amount, memo) + +tx := transaction.NewBuilder(big.NewInt(42429)). + SetNonce(nonce). + SetGas(100000). + SetMaxFeePerGas(big.NewInt(10000000000)). + SetMaxPriorityFeePerGas(big.NewInt(1000000000)). + AddCall(transaction.AlphaUSDAddress, big.NewInt(0), memoData). + Build() + +func encodeTransferWithMemo(to common.Address, amount *big.Int, memo [32]byte) []byte { + data := make([]byte, 100) + copy(data[0:4], []byte{0x63, 0x3e, 0xb4, 0x08}) // transferWithMemo(address,uint256,bytes32) + copy(data[16:36], to.Bytes()) + amount.FillBytes(data[36:68]) + copy(data[68:100], memo[:]) + return data +} +``` ### Batch Multiple Calls -Tempo transactions can batch multiple calls into a single transaction: +Execute multiple operations atomically in a single transaction: ```go [batch.go] -tx := transaction.NewDefault(42431) // Tempo testnet -tx.Gas = 150000 -tx.Calls = []transaction.Call{ - {To: &addr1, Value: big.NewInt(0), Data: transfer1Data}, - {To: &addr2, Value: big.NewInt(0), Data: transfer2Data}, - {To: &addr3, Value: big.NewInt(0), Data: contractCallData}, -} +tx := transaction.NewBuilder(big.NewInt(42429)). + SetNonce(nonce). + SetGas(200000). + SetMaxFeePerGas(big.NewInt(10000000000)). + SetMaxPriorityFeePerGas(big.NewInt(1000000000)). + AddCall(addr1, big.NewInt(0), transfer1Data). + AddCall(addr2, big.NewInt(0), transfer2Data). + AddCall(addr3, big.NewInt(0), contractCallData). + Build() + +transaction.SignTransaction(tx, s) +``` -transaction.SignTransaction(tx, signer) -client.SendTransaction(tx) +### Parallel Transactions (2D Nonces) + +Send multiple transactions concurrently using different nonce keys: + +```go [parallel.go] +tx1 := transaction.NewBuilder(big.NewInt(42429)). + SetNonceKey(big.NewInt(1)). // Sequence A + SetNonce(0). + SetGas(100000). + SetMaxFeePerGas(big.NewInt(10000000000)). + SetMaxPriorityFeePerGas(big.NewInt(1000000000)). + AddCall(recipient1, big.NewInt(0), data1). + Build() + +tx2 := transaction.NewBuilder(big.NewInt(42429)). + SetNonceKey(big.NewInt(2)). // Sequence B (parallel) + SetNonce(0). + SetGas(100000). + SetMaxFeePerGas(big.NewInt(10000000000)). + SetMaxPriorityFeePerGas(big.NewInt(1000000000)). + AddCall(recipient2, big.NewInt(0), data2). + Build() + +transaction.SignTransaction(tx1, s) +transaction.SignTransaction(tx2, s) + +// Send both in parallel +go func() { c.SendRawTransaction(ctx, serialize(tx1)) }() +go func() { c.SendRawTransaction(ctx, serialize(tx2)) }() ``` ### Fee Sponsorship -Have another account pay for transaction fees using a fee payer: +Have another account pay for transaction fees: ```go [feepayer.go] -tx := transaction.NewDefault(42431) -transaction.SignTransaction(tx, userSigner) +tx := transaction.NewBuilder(big.NewInt(42429)). + SetNonce(nonce). + SetGas(100000). + SetMaxFeePerGas(big.NewInt(10000000000)). + SetMaxPriorityFeePerGas(big.NewInt(1000000000)). + SetSponsored(true). // Mark as awaiting fee payer + AddCall(recipient, big.NewInt(0), data). + Build() +transaction.SignTransaction(tx, userSigner) transaction.AddFeePayerSignature(tx, feePayerSigner) - -client.SendTransaction(tx) ``` ### Transaction Validity Window @@ -162,14 +267,33 @@ client.SendTransaction(tx) Set a time window during which the transaction is valid: ```go [validity.go] -import "time" +now := time.Now() + +tx := transaction.NewBuilder(big.NewInt(42429)). + SetNonce(nonce). + SetGas(100000). + SetMaxFeePerGas(big.NewInt(10000000000)). + SetMaxPriorityFeePerGas(big.NewInt(1000000000)). + SetValidAfter(uint64(now.Unix())). + SetValidBefore(uint64(now.Add(1 * time.Hour).Unix())). + AddCall(recipient, big.NewInt(0), data). + Build() +``` -tx := transaction.NewDefault(42431) -tx.ValidAfter = uint64(time.Now().Unix()) -tx.ValidBefore = uint64(time.Now().Add(1 * time.Hour).Unix()) +### Batch RPC Requests -transaction.SignTransaction(tx, signer) -client.SendTransaction(tx) +Send multiple RPC calls efficiently in a single HTTP request: + +```go [batch_rpc.go] +batch := client.NewBatchRequest() +batch.Add("eth_blockNumber"). + Add("eth_chainId"). + Add("eth_getBalance", "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb", "latest") + +responses, _ := c.SendBatch(ctx, batch) +for _, resp := range responses { + fmt.Printf("Result: %v\n", resp.Result) +} ``` ## Packages From e30ea65bfc0e28faa545c363894811304c05e22b Mon Sep 17 00:00:00 2001 From: Brendan Ryan Date: Tue, 3 Feb 2026 17:05:58 -0800 Subject: [PATCH 2/4] sol in config --- vocs.config.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vocs.config.ts b/vocs.config.ts index abf1ccda..017c788e 100644 --- a/vocs.config.ts +++ b/vocs.config.ts @@ -717,6 +717,11 @@ export default defineConfig({ status: 301, }, ], + codeHighlight: { + langAlias: { + sol: 'solidity', + }, + }, twoslash: { twoslashOptions: { compilerOptions: { From 1f3dedf55aad4396a539cc33ec49897dfc4003ff Mon Sep 17 00:00:00 2001 From: Brendan Ryan Date: Tue, 3 Feb 2026 17:23:41 -0800 Subject: [PATCH 3/4] tighten docs --- src/pages/sdk/go/index.mdx | 69 +++++++++++++++++--------------------- vocs.config.ts | 7 ++++ 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/pages/sdk/go/index.mdx b/src/pages/sdk/go/index.mdx index 3dbdb2ec..1cf04191 100644 --- a/src/pages/sdk/go/index.mdx +++ b/src/pages/sdk/go/index.mdx @@ -38,11 +38,11 @@ import ( ) func main() { - c := client.New("https://rpc.testnet.tempo.xyz") // [!code focus] + c := client.New("https://rpc.testnet.tempo.xyz") ctx := context.Background() - blockNum, _ := c.GetBlockNumber(ctx) // [!code focus] - fmt.Printf("Connected to Tempo at block %d\n", blockNum) // [!code focus] + blockNum, _ := c.GetBlockNumber(ctx) + fmt.Printf("Connected to Tempo at block %d\n", blockNum) } ``` @@ -68,10 +68,10 @@ import ( ) func main() { - s, err := signer.NewSigner("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80") // [!code focus] - if err != nil { // [!code focus] - panic(err) // [!code focus] - } // [!code focus] + s, err := signer.NewSigner("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80") + if err != nil { + panic(err) + } fmt.Printf("Address: %s\n", s.Address().Hex()) } @@ -100,11 +100,11 @@ func main() { s, _ := signer.NewSigner("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80") ctx := context.Background() - nonce, _ := c.GetTransactionCount(ctx, s.Address().Hex()) // [!code focus] + nonce, _ := c.GetTransactionCount(ctx, s.Address().Hex()) // [!code hl] recipient := common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8") - // [!code focus:10] + // [!code hl:10] tx := transaction.NewBuilder(big.NewInt(42429)). // Tempo testnet SetNonce(nonce). SetGas(100000). @@ -115,7 +115,7 @@ func main() { transaction.SignTransaction(tx, s) serialized, _ := transaction.Serialize(tx, nil) - hash, _ := c.SendRawTransaction(ctx, serialized) // [!code focus] + hash, _ := c.SendRawTransaction(ctx, serialized) // [!code hl] log.Printf("Transaction hash: %s", hash) } ``` @@ -140,14 +140,19 @@ fmt.Printf("Block: %d, Chain: %d, Nonce: %d\n", blockNum, chainID, nonce) ### Token Transfer -Send a TIP-20 token transfer using ABI-encoded calldata: +Send a TIP-20 token transfer using go-ethereum's ABI encoding: ```go [transfer.go] +import "github.com/ethereum/go-ethereum/accounts/abi" + +erc20ABI, _ := abi.JSON(strings.NewReader(`[{"name":"transfer","type":"function","inputs":[{"name":"to","type":"address"},{"name":"amount","type":"uint256"}]}]`)) + recipient := common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8") amount := big.NewInt(100_000_000) // 100 tokens (6 decimals) -transferData := encodeTransfer(recipient, amount) +transferData, _ := erc20ABI.Pack("transfer", recipient, amount) +// [!code hl:start] tx := transaction.NewBuilder(big.NewInt(42429)). SetNonce(nonce). SetGas(100000). @@ -155,14 +160,7 @@ tx := transaction.NewBuilder(big.NewInt(42429)). SetMaxPriorityFeePerGas(big.NewInt(1000000000)). AddCall(transaction.AlphaUSDAddress, big.NewInt(0), transferData). Build() - -func encodeTransfer(to common.Address, amount *big.Int) []byte { - data := make([]byte, 68) - copy(data[0:4], []byte{0xa9, 0x05, 0x9c, 0xbb}) // transfer(address,uint256) - copy(data[16:36], to.Bytes()) - amount.FillBytes(data[36:68]) - return data -} +// [!code hl:end] ``` ### Transfer with Memo @@ -170,13 +168,16 @@ func encodeTransfer(to common.Address, amount *big.Int) []byte { Include a memo for payment reconciliation: ```go [memo.go] +tip20ABI, _ := abi.JSON(strings.NewReader(`[{"name":"transferWithMemo","type":"function","inputs":[{"name":"to","type":"address"},{"name":"amount","type":"uint256"},{"name":"memo","type":"bytes32"}]}]`)) + recipient := common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8") amount := big.NewInt(100_000_000) memo := [32]byte{} copy(memo[:], "INV-12345") -memoData := encodeTransferWithMemo(recipient, amount, memo) +memoData, _ := tip20ABI.Pack("transferWithMemo", recipient, amount, memo) +// [!code hl:start] tx := transaction.NewBuilder(big.NewInt(42429)). SetNonce(nonce). SetGas(100000). @@ -184,15 +185,7 @@ tx := transaction.NewBuilder(big.NewInt(42429)). SetMaxPriorityFeePerGas(big.NewInt(1000000000)). AddCall(transaction.AlphaUSDAddress, big.NewInt(0), memoData). Build() - -func encodeTransferWithMemo(to common.Address, amount *big.Int, memo [32]byte) []byte { - data := make([]byte, 100) - copy(data[0:4], []byte{0x63, 0x3e, 0xb4, 0x08}) // transferWithMemo(address,uint256,bytes32) - copy(data[16:36], to.Bytes()) - amount.FillBytes(data[36:68]) - copy(data[68:100], memo[:]) - return data -} +// [!code hl:end] ``` ### Batch Multiple Calls @@ -205,9 +198,9 @@ tx := transaction.NewBuilder(big.NewInt(42429)). SetGas(200000). SetMaxFeePerGas(big.NewInt(10000000000)). SetMaxPriorityFeePerGas(big.NewInt(1000000000)). - AddCall(addr1, big.NewInt(0), transfer1Data). - AddCall(addr2, big.NewInt(0), transfer2Data). - AddCall(addr3, big.NewInt(0), contractCallData). + AddCall(addr1, big.NewInt(0), transfer1Data). // [!code hl] + AddCall(addr2, big.NewInt(0), transfer2Data). // [!code hl] + AddCall(addr3, big.NewInt(0), contractCallData). // [!code hl] Build() transaction.SignTransaction(tx, s) @@ -219,7 +212,7 @@ Send multiple transactions concurrently using different nonce keys: ```go [parallel.go] tx1 := transaction.NewBuilder(big.NewInt(42429)). - SetNonceKey(big.NewInt(1)). // Sequence A + SetNonceKey(big.NewInt(1)). // Sequence A // [!code hl] SetNonce(0). SetGas(100000). SetMaxFeePerGas(big.NewInt(10000000000)). @@ -228,7 +221,7 @@ tx1 := transaction.NewBuilder(big.NewInt(42429)). Build() tx2 := transaction.NewBuilder(big.NewInt(42429)). - SetNonceKey(big.NewInt(2)). // Sequence B (parallel) + SetNonceKey(big.NewInt(2)). // Sequence B (parallel) // [!code hl] SetNonce(0). SetGas(100000). SetMaxFeePerGas(big.NewInt(10000000000)). @@ -254,7 +247,7 @@ tx := transaction.NewBuilder(big.NewInt(42429)). SetGas(100000). SetMaxFeePerGas(big.NewInt(10000000000)). SetMaxPriorityFeePerGas(big.NewInt(1000000000)). - SetSponsored(true). // Mark as awaiting fee payer + SetSponsored(true). // Mark as awaiting fee payer // [!code hl] AddCall(recipient, big.NewInt(0), data). Build() @@ -274,8 +267,8 @@ tx := transaction.NewBuilder(big.NewInt(42429)). SetGas(100000). SetMaxFeePerGas(big.NewInt(10000000000)). SetMaxPriorityFeePerGas(big.NewInt(1000000000)). - SetValidAfter(uint64(now.Unix())). - SetValidBefore(uint64(now.Add(1 * time.Hour).Unix())). + SetValidAfter(uint64(now.Unix())). // [!code hl] + SetValidBefore(uint64(now.Add(1 * time.Hour).Unix())). // [!code hl] AddCall(recipient, big.NewInt(0), data). Build() ``` diff --git a/vocs.config.ts b/vocs.config.ts index 017c788e..900c8ed2 100644 --- a/vocs.config.ts +++ b/vocs.config.ts @@ -730,4 +730,11 @@ export default defineConfig({ }, }, }, + markdown: { + code: { + langAlias: { + sol: 'solidity', + }, + }, + }, }) From 6e4ae20035d36de8e2fcc318e24b4182c2c7bec0 Mon Sep 17 00:00:00 2001 From: Brendan Ryan Date: Tue, 3 Feb 2026 17:32:10 -0800 Subject: [PATCH 4/4] remove transfer --- src/pages/sdk/go/index.mdx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/pages/sdk/go/index.mdx b/src/pages/sdk/go/index.mdx index 1cf04191..b4c8c3f4 100644 --- a/src/pages/sdk/go/index.mdx +++ b/src/pages/sdk/go/index.mdx @@ -152,7 +152,6 @@ amount := big.NewInt(100_000_000) // 100 tokens (6 decimals) transferData, _ := erc20ABI.Pack("transfer", recipient, amount) -// [!code hl:start] tx := transaction.NewBuilder(big.NewInt(42429)). SetNonce(nonce). SetGas(100000). @@ -160,7 +159,6 @@ tx := transaction.NewBuilder(big.NewInt(42429)). SetMaxPriorityFeePerGas(big.NewInt(1000000000)). AddCall(transaction.AlphaUSDAddress, big.NewInt(0), transferData). Build() -// [!code hl:end] ``` ### Transfer with Memo @@ -177,7 +175,6 @@ copy(memo[:], "INV-12345") memoData, _ := tip20ABI.Pack("transferWithMemo", recipient, amount, memo) -// [!code hl:start] tx := transaction.NewBuilder(big.NewInt(42429)). SetNonce(nonce). SetGas(100000). @@ -185,7 +182,6 @@ tx := transaction.NewBuilder(big.NewInt(42429)). SetMaxPriorityFeePerGas(big.NewInt(1000000000)). AddCall(transaction.AlphaUSDAddress, big.NewInt(0), memoData). Build() -// [!code hl:end] ``` ### Batch Multiple Calls