Skip to content

Commit 4fac8d7

Browse files
authored
Updating readme to match latest code (#78)
1 parent 266dced commit 4fac8d7

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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 (
9293
func 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
}

sdk-clients/aggregation/models.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import (
99
type SwapResponseExtended struct {
1010
SwapResponse
1111

12-
TxNormalized NormalizedTransactionData
12+
TxNormalized NormalizedTransactionData `json:"txNormalized"`
1313
}
1414

1515
type NormalizedTransactionData struct {
16-
Data []byte
17-
Gas uint64
18-
GasPrice *big.Int
19-
To gethCommon.Address
20-
Value *big.Int
16+
Data []byte `json:"data"`
17+
Gas uint64 `json:"gas"`
18+
GasPrice *big.Int `json:"gasPrice"`
19+
To gethCommon.Address `json:"to"`
20+
Value *big.Int `json:"value"`
2121
}
2222

2323
type ApproveCallDataResponseExtended struct {

0 commit comments

Comments
 (0)