Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions examples/typed_transfer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) 2026 IoTeX
// This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
// or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
// This source code is governed by Apache License 2.0 that can be found in the LICENSE file.

// Example: send a typed (EIP-1559 DynamicFee) transfer on the IoTeX testnet.
//
// IOTEX_KEY=<funded-private-key-hex> go run ./examples/typed_transfer
//
// The same chained API works for AccessList (TxType=1) by calling
// SetTxType(1) and SetGasPrice instead of SetGasTipCap/SetGasFeeCap.
package main

import (
"context"
"fmt"
"log"
"math/big"
"os"

"github.com/iotexproject/iotex-address/address"
"github.com/iotexproject/iotex-proto/golang/iotexapi"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"

"github.com/iotexproject/iotex-antenna-go/v2/account"
"github.com/iotexproject/iotex-antenna-go/v2/iotex"
)

const (
endpoint = "api.testnet.iotex.one:443"
recipient = "io1emxf8zzqckhgjde6dqd97ts0y3q496gm3fdrl6"
chainID = 2

// DynamicFee in iotex's EIP-1559 model: TxType=2 selects DynamicFee,
// the tip is what the sender is willing to pay above the base fee, and
// the fee cap is the maximum total per-gas price the sender will pay.
dynamicFeeTxType = 2
)

func main() {
key := os.Getenv("IOTEX_KEY")
if key == "" {
log.Fatal("set IOTEX_KEY to a funded testnet private key (hex, no 0x prefix)")
}

acc, err := account.HexStringToAccount(key)
if err != nil {
log.Fatalf("invalid private key: %v", err)
}
to, err := address.FromString(recipient)
if err != nil {
log.Fatalf("invalid recipient: %v", err)
}

creds := credentials.NewClientTLSFromCert(nil, "")
conn, err := grpc.NewClient(endpoint, grpc.WithTransportCredentials(creds))
if err != nil {
log.Fatalf("grpc dial: %v", err)
}
defer conn.Close()
cli := iotex.NewAuthedClient(iotexapi.NewAPIServiceClient(conn), chainID, acc)

tip := new(big.Int).SetUint64(1_000_000_000_000) // 1 Qev (10^12)
feeCap := new(big.Int).Mul(big.NewInt(2), tip)

hash, err := cli.Transfer(to, big.NewInt(1)).
SetTxType(dynamicFeeTxType).
SetGasTipCap(tip).
SetGasFeeCap(feeCap).
SetGasLimit(50_000).
Call(context.Background())
if err != nil {
log.Fatalf("send: %v", err)
}
fmt.Printf("sent DynamicFee transfer: %x\n", hash[:])
}
59 changes: 29 additions & 30 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,51 +1,50 @@
module github.com/iotexproject/iotex-antenna-go/v2

go 1.21.11
go 1.23.0

require (
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/ethereum/go-ethereum v1.10.26
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang/mock v1.4.4
github.com/golang/protobuf v1.5.3
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0
github.com/iotexproject/go-pkgs v0.1.13
github.com/iotexproject/iotex-address v0.2.8
github.com/iotexproject/iotex-proto v0.5.10
github.com/golang/protobuf v1.5.4
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/holiman/uint256 v1.3.2
github.com/iotexproject/go-pkgs v0.1.16-0.20250813094138-d89b145b833c
github.com/iotexproject/iotex-address v0.2.9-0.20251203033311-6e8aa4fd43ef
github.com/iotexproject/iotex-proto v0.6.6-0.20260211020747-f26bd969ed16
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
golang.org/x/crypto v0.31.0
google.golang.org/grpc v1.33.1
google.golang.org/protobuf v1.27.1
github.com/stretchr/testify v1.10.0
go.uber.org/mock v0.5.2
google.golang.org/grpc v1.69.4
google.golang.org/protobuf v1.36.6
)

require (
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/bits-and-blooms/bitset v1.20.0 // indirect
github.com/consensys/bavard v0.1.27 // indirect
github.com/consensys/gnark-crypto v0.16.0 // indirect
github.com/crate-crypto/go-eth-kzg v1.3.0 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/dustinxie/gmsm v1.4.0 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/erigontech/secp256k1 v1.1.0 // indirect
github.com/ethereum/c-kzg-4844/v2 v2.1.0 // indirect
github.com/ethereum/go-verkle v0.2.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto v0.0.0-20201211151036-40ec1c210f7a // indirect
github.com/supranational/blst v0.3.15 // indirect
golang.org/x/crypto v0.35.0 // indirect
golang.org/x/net v0.36.0 // indirect
golang.org/x/sync v0.11.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
google.golang.org/genproto v0.0.0-20230127162408-596548ed4efa // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/ethereum/go-ethereum => github.com/iotexproject/go-ethereum v0.5.0
replace github.com/ethereum/go-ethereum => github.com/iotexproject/go-ethereum v1.7.4-0.20260114032628-a8ad6229e289
Loading
Loading