Skip to content

tempoxyz/tempo-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


tempo combomark



tempo-go

Go SDK for building applications on Tempo

Contents

Installation

go get github.com/tempoxyz/tempo-go

Quick Start

package main

import (
    "fmt"
    "math/big"

    "github.com/ethereum/go-ethereum/common"
    "github.com/tempoxyz/tempo-go/pkg/client"
    "github.com/tempoxyz/tempo-go/pkg/signer"
    "github.com/tempoxyz/tempo-go/pkg/transaction"
)

func main() {
    // Create RPC client
    c, _ := client.New("https://rpc.testnet.tempo.xyz")

    s, _ := signer.NewSigner("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")

    recipient := common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8")
    amount := new(big.Int).Mul(big.NewInt(10), big.NewInt(1e18)) // 10 AlphaUSD (18 decimals)
    transferData := buildERC20TransferData(recipient, amount)

    tx := transaction.New()
    tx.ChainID = big.NewInt(42429) // 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,
    }}

    transaction.SignTransaction(tx, s)
    hash, _ := c.SendTransaction(tx)
    fmt.Printf("Transaction hash: %s\n", hash.Hex())
}

// buildERC20TransferData creates calldata for ERC20 transfer(address,uint256)
func buildERC20TransferData(to common.Address, amount *big.Int) []byte {
    // transfer(address,uint256) selector: 0xa9059cbb
    data := make([]byte, 68)
    data[0], data[1], data[2], data[3] = 0xa9, 0x05, 0x9c, 0xbb
    copy(data[16:36], to.Bytes())              // address (32 bytes, left-padded)
    amount.FillBytes(data[36:68])              // uint256 (32 bytes)
    return data
}

Example Usage

Use Case Example
Basic Transfer examples/simple-send
Fee Sponsorship examples/feepayer
Batch Calls See transaction tests

Basic Transfer

tx := transaction.NewDefault(42429)
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, // ERC20 transfer calldata
}}

transaction.SignTransaction(tx, signer)

client.SendTransaction(tx)

Sponsored Transaction

tx := transaction.NewDefault(42429)
transaction.SignTransaction(tx, userSigner)

transaction.AddFeePayerSignature(tx, feePayerSigner)

client.SendTransaction(tx)

Batch Multiple Calls

tx := transaction.NewDefault(42429) // 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},
}

transaction.SignTransaction(tx, signer)
client.SendTransaction(tx)

Transaction with Validity Window

tx := transaction.NewDefault(42429) // Tempo testnet
tx.ValidAfter = uint64(time.Now().Unix())
tx.ValidBefore = uint64(time.Now().Add(1 * time.Hour).Unix())

transaction.SignTransaction(tx, signer)
client.SendTransaction(tx)

Packages

Package Description Documentation
transaction TempoTransaction encoding, signing, and validation README
client RPC client for interacting with Tempo nodes GoDoc
signer Key management and signature generation GoDoc

Testing

Run Unit Tests

make test

Run Tests with Coverage

make test-coverage

Run All Checks (format, vet, tests)

make check

Run Integration Tests

# Start local Tempo node
docker-compose up -d

# Run integration tests
make integration

# Stop node
docker-compose down

External Resources

API Reference

View documentation locally:

make docs
# Opens at http://localhost:6060/pkg/github.com/tempoxyz/tempo-go/

Full API documentation is also available on pkg.go.dev.

Development Setup

Prerequisites

  • Go 1.21 or higher
  • Make

Building

git clone https://github.com/tempoxyz/tempo-go.git
cd tempo-go

go mod download

make check

Running Examples

# Build all examples
make build_examples

# Run the simple-send example
./bin/simple-send

# Run the fee payer server
./bin/feepayer

Code Formatting

make fix

Contributing

Our contributor guidelines can be found in CONTRIBUTING.md.

Security

See SECURITY.md. Note: Tempo is still undergoing audit and does not have an active bug bounty. Submissions will not be eligible for a bounty until audits have concluded.

License

Licensed under either of Apache License, Version 2.0 or MIT License at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in these crates by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Go SDK for the Tempo blockchain

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Contributing

Security policy

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •  

Languages