1inch-sdk-go

module
v5.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2026 License: MIT

README

Dev Portal Go SDK

The SDK requires a minimum version of Go 1.25.

Check out the release notes for information about the latest bug fixes, updates, and features added to the SDK.

Beyond simplifying Go-based interactions with our REST API, this SDK broadcasts transactions to the network, signs gasless approvals (EIP-2612 permits and Permit2), and places gasless swaps through Fusion and cross-chain swaps through Fusion+. Each client has examples of how to send valid requests to each Dev Portal endpoint.

Jump To:

Supported APIs

Token Swaps

Classic Swap API - [Docs | SDK Example]

Intent-based Swap (Fusion) API - [Docs | SDK Example]

Cross-chain Swap (Fusion+) API - [Docs | SDK Example]

Orderbook API - [Docs | SDK Example]

Infrastructure

Balance API - [Docs | SDK Example]

Gas Price API - [Docs | SDK Example]

History API [Docs | SDK Example]

NFT API - [Docs | SDK Example]

Portfolio API - [Docs | SDK Example]

Spot Price API - [Docs | SDK Example]

Token API - [Docs | SDK Example]

Traces API - [Docs | SDK Example]

Transaction Gateway API - [Docs | SDK Example]

Web3 RPC API - [Docs | SDK Example]

Getting started

To get started working with the SDK, set up your project for Go modules and retrieve the SDK dependencies with go get.

This example shows how you can use the SDK in a new project to fetch swap data for trading 100 USDC to 1INCH on Ethereum:

Initialize Project
mkdir ~/hello1inch
cd ~/hello1inch
go mod init hello1inch
Add SDK Dependencies
go get github.com/1inch/1inch-sdk-go/v5/sdk-clients/aggregation
Write Code

In your preferred editor, add the following content to main.go and update the devPortalToken variable to use your own Dev Portal Token.

Note: The 1inch Dev Portal Token can be generated at https://business.1inch.com/portal

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"log"

	"github.com/1inch/1inch-sdk-go/v5/constants"
	"github.com/1inch/1inch-sdk-go/v5/sdk-clients/aggregation"
)

var (
	devPortalToken = "insert_your_dev_portal_token_here" // After initial testing, update this to read from your local environment using a function like os.GetEnv()
)

func main() {
	rpcUrl := "https://ethereum-rpc.publicnode.com"
	// Throwaway placeholder key, used only to derive an address for the request
	randomPrivateKey := "e8f32e723decf4051aefac8e6c1a25ad146334449d2792c2b8b15d0b59c2a35f"

	config, err := aggregation.NewConfiguration(aggregation.ConfigurationParams{
		NodeUrl:    rpcUrl,
		PrivateKey: randomPrivateKey,
		ChainId:    constants.EthereumChainId,
		ApiUrl:     "https://api.1inch.com",
		ApiKey:     devPortalToken,
	})
	if err != nil {
		log.Fatalf("Failed to create configuration: %v\n", err)
	}
	client, err := aggregation.NewClient(config)
	if err != nil {
		log.Fatalf("Failed to create client: %v\n", err)
	}
	ctx := context.Background()

	swapData, err := client.GetSwap(ctx, aggregation.GetSwapParams{
		Src:             "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC
		Dst:             "0x111111111117dc0aa78b770fa6a738034120c302", // 1INCH
		Amount:          "100000000",
		From:            client.Wallet.Address().Hex(),
		Slippage:        1,
		DisableEstimate: true,
	})
	if err != nil {
		log.Fatalf("Failed to get swap data: %v\n", err)
	}

	output, err := json.MarshalIndent(swapData, "", "  ")
	if err != nil {
		log.Fatalf("Failed to marshal swap data: %v\n", err)
	}
	fmt.Printf("%s\n", string(output))
}
Compile and Execute
go run .

Documentation for all API calls can be found at https://business.1inch.com/portal/documentation

Each folder inside the sdk-clients directory will contain an SDK for one of the 1inch APIs and will also include dedicated examples.

Getting Help

If you have questions, want to discuss the tool, or have found a bug, please open an issue here on GitHub

Development

Please see our SDK Developer Guide if you would like to contribute

Directories

Path Synopsis
Package codegen generates the SDK's *_types.gen.go files from the OpenAPI specs in codegen/openapi.
Package codegen generates the SDK's *_types.gen.go files from the OpenAPI specs in codegen/openapi.
cmd/fetch-specs command
Command fetch-specs refreshes the local OpenAPI spec copies from the 1inch Dev Portal and records their provenance in codegen/specs.lock.json.
Command fetch-specs refreshes the local OpenAPI spec copies from the 1inch Dev Portal and records their provenance in codegen/specs.lock.json.
cmd/generate-types command
Command generate-types regenerates all *_types.gen.go files from the OpenAPI specs in codegen/openapi.
Command generate-types regenerates all *_types.gen.go files from the OpenAPI specs in codegen/openapi.
internal
version
Package version holds the SDK's single source-of-truth version.
Package version holds the SDK's single source-of-truth version.
sdk-clients
aggregation
Package aggregation provides primitives to interact with the openapi HTTP API.
Package aggregation provides primitives to interact with the openapi HTTP API.
balances
Package balances provides primitives to interact with the openapi HTTP API.
Package balances provides primitives to interact with the openapi HTTP API.
fusion
Package fusion provides primitives to interact with the openapi HTTP API.
Package fusion provides primitives to interact with the openapi HTTP API.
fusionplus
Package fusionplus provides primitives to interact with the openapi HTTP API.
Package fusionplus provides primitives to interact with the openapi HTTP API.
gasprices
Package gasprices provides primitives to interact with the openapi HTTP API.
Package gasprices provides primitives to interact with the openapi HTTP API.
history
Package history provides primitives to interact with the openapi HTTP API.
Package history provides primitives to interact with the openapi HTTP API.
nft
Package nft provides primitives to interact with the openapi HTTP API.
Package nft provides primitives to interact with the openapi HTTP API.
orderbook
Package orderbook provides primitives to interact with the openapi HTTP API.
Package orderbook provides primitives to interact with the openapi HTTP API.
portfolio
Package portfolio provides primitives to interact with the openapi HTTP API.
Package portfolio provides primitives to interact with the openapi HTTP API.
spotprices
Package spotprices provides primitives to interact with the openapi HTTP API.
Package spotprices provides primitives to interact with the openapi HTTP API.
tokens
Package tokens provides primitives to interact with the openapi HTTP API.
Package tokens provides primitives to interact with the openapi HTTP API.
traces
Package traces provides primitives to interact with the openapi HTTP API.
Package traces provides primitives to interact with the openapi HTTP API.
txbroadcast
Package txbroadcast provides primitives to interact with the openapi HTTP API.
Package txbroadcast provides primitives to interact with the openapi HTTP API.
web3
Package web3 provides primitives to interact with the openapi HTTP API.
Package web3 provides primitives to interact with the openapi HTTP API.
tools
wiredump command
Command wiredump prints the SDK's wire surface: every exported struct field of every package under the given root, with its Go type and struct tag, as deterministic JSON.
Command wiredump prints the SDK's wire surface: every exported struct field of every package under the given root, with its Go type and struct tag, as deterministic JSON.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL