Skip to content

Latest commit

 

History

History
132 lines (91 loc) · 4.77 KB

README.md

File metadata and controls

132 lines (91 loc) · 4.77 KB

Dev Portal Go SDK

The SDK requires a minimum version of Go 1.21.

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

This is a Go SDK to simplify interactions with the 1inch Dev Portal APIs. When complete, it will support all endpoints tracked by our official docs here.

Beyond mirroring the Developer Portal APIs, this SDK also supports token approvals, permit signature generation, and the execution of 1inch swaps onchain for EOA wallets.

Jump To:

Supported APIs

Swap API - [Docs | SDK Example]

Orderbook API - [Docs | SDK Example]

Balances API - [Docs | SDK Example]

Gas Price API - [Docs | SDK Example]

NFT API - [Docs | SDK Example]

Transaction Gateway 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 request a quote to swap 1 USDC for DAI on Ethereum:

Initialize Project
mkdir ~/hello1inch
cd ~/hello1inch
go mod init hello1inch
Add SDK Dependencies
go get github.com/1inch/1inch-sdk-go/sdk-clients/aggregation@globally-refactored-main
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://portal.1inch.dev

package main

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

	"github.com/1inch/1inch-sdk-go/constants"
	"github.com/1inch/1inch-sdk-go/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://eth.llamarpc.com"
	randomPrivateKey := "e8f32e723decf4051aefac8e6c1a25ad146334449d2792c2b8b15d0b59c2a35f"
	
	config, err := aggregation.NewConfiguration(rpcUrl, randomPrivateKey, constants.EthereumChainId, "https://api.1inch.dev", devPortalToken)
	if err != nil {
		fmt.Printf("Failed to create configuration: %v\n", err)
		return
	}
	client, err := aggregation.NewClient(config)

	ctx := context.Background()

	swapData, err := client.GetSwap(ctx, aggregation.GetSwapParams{
		Src:             "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
		Dst:             "0x6b175474e89094c44da98b954eedeac495271d0f",
		Amount:          "1000000",
		From:            client.Wallet.Address().Hex(),
		Slippage:        1,
		DisableEstimate: true,
	})
	if err != nil {
		fmt.Printf("Failed to get swap data: %v\n", err)
		return
	}

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

Documentation for all API calls can be found at https://portal.1inch.dev/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