@@ -80,6 +80,7 @@ import (
8080 " context"
8181 " encoding/json"
8282 " fmt"
83+ " log"
8384
8485 " github.com/1inch/1inch-sdk-go/constants"
8586 " github.com/1inch/1inch-sdk-go/sdk-clients/aggregation"
@@ -92,33 +93,38 @@ var (
9293func main () {
9394 rpcUrl := " https://eth.llamarpc.com"
9495 randomPrivateKey := " e8f32e723decf4051aefac8e6c1a25ad146334449d2792c2b8b15d0b59c2a35f"
95-
96- config , err := aggregation.NewConfiguration (rpcUrl, randomPrivateKey, constants.EthereumChainId , " https://api.1inch.dev" , devPortalToken)
96+
97+ config , err := aggregation.NewConfiguration (aggregation.ConfigurationParams {
98+ NodeUrl: rpcUrl,
99+ PrivateKey: randomPrivateKey,
100+ ChainId: constants.EthereumChainId ,
101+ ApiUrl: " https://api.1inch.dev" ,
102+ ApiKey: devPortalToken,
103+ })
97104 if err != nil {
98- fmt.Printf (" Failed to create configuration: %v \n " , err)
99- return
105+ log.Fatalf (" Failed to create configuration: %v \n " , err)
100106 }
101107 client , err := aggregation.NewClient (config)
102-
108+ if err != nil {
109+ log.Fatalf (" Failed to create client: %v \n " , err)
110+ }
103111 ctx := context.Background ()
104112
105113 swapData , err := client.GetSwap (ctx, aggregation.GetSwapParams {
106- Src: " 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" ,
107- Dst: " 0x6b175474e89094c44da98b954eedeac495271d0f " ,
108- Amount: " 1000000 " ,
114+ Src: " 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" , // USDC
115+ Dst: " 0x111111111117dc0aa78b770fa6a738034120c302 " , // 1INCH
116+ Amount: " 100000000 " ,
109117 From: client.Wallet .Address ().Hex (),
110118 Slippage: 1 ,
111119 DisableEstimate: true ,
112120 })
113121 if err != nil {
114- fmt.Printf (" Failed to get swap data: %v \n " , err)
115- return
122+ log.Fatalf (" Failed to get swap data: %v \n " , err)
116123 }
117124
118125 output , err := json.MarshalIndent (swapData, " " , " " )
119126 if err != nil {
120- fmt.Printf (" Failed to marshal swap data: %v \n " , err)
121- return
127+ log.Fatalf (" Failed to marshal swap data: %v \n " , err)
122128 }
123129 fmt.Printf (" %s \n " , string (output))
124130}
0 commit comments