Skip to content

Latest commit

 

History

History
148 lines (103 loc) · 6.17 KB

README.md

File metadata and controls

148 lines (103 loc) · 6.17 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.

Beyond simplifying Go-based interactions with our REST API, this SDK also helps broadcast transactions to the network, can generate Permit1 signatures to skip the need for Approval transactions, and enables access to our Fusion system. Each SDK has examples of how to send valid requests to each Dev Portal endpoint.

Jump To:

Supported APIs

Token Swaps

Swap API - [Docs | SDK Example]

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

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]

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
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"
	"log"

	"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(aggregation.ConfigurationParams{
		NodeUrl:    rpcUrl,
		PrivateKey: randomPrivateKey,
		ChainId:    constants.EthereumChainId,
		ApiUrl:     "https://api.1inch.dev",
		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://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