Skip to content

Repository files navigation

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/v4/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/v4/constants"
	"github.com/1inch/1inch-sdk-go/v4/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

About

SDK of 1inch APIs for golang

Resources

Stars

24 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages