Skip to content

Commit

Permalink
docs: create an order with smart-contract wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
shoom3301 committed Dec 11, 2024
1 parent 6fc34fd commit 31b1498
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/trading/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,52 @@ const { quoteResults } = await sdk.getQuote(parameters)
console.log('Quote:', quoteResults)
````

### Create an order with smart-contract wallet

If you want to create an order with a smart-contract wallet, you should specify the `signingScheme` parameter in the `postSwapOrder` function.
And then you need to send a transaction from `getPreSignTransaction` result in order to sign the order.

#### Example

```typescript
import {
SupportedChainId,
OrderKind,
TradeParameters,
TradingSdk
} from '@cowprotocol/cow-sdk'
const sdk = new TradingSdk({
chainId: SupportedChainId.SEPOLIA,
signer: '<privateKeyOrEthersSigner>',
appCode: '<YOUR_APP_CODE>',
})
const parameters: TradeParameters = {
kind: OrderKind.BUY,
sellToken: '0xfff9976782d46cc05630d1f6ebab18b2324d6b14',
sellTokenDecimals: 18,
buyToken: '0x0625afb445c3b6b7b929342a04a22599fd5dbb59',
buyTokenDecimals: 18,
amount: '120000000000000000'
}
const advancedParameters: SwapAdvancedSettings = {
quoteRequest: {
// Specify the signing scheme
signingScheme: SigningScheme.PRESIGN
}
}
const smartContractWalletAddress = '0x<smartContractWalletAddress>'
const orderId = await sdk.postSwapOrder(parameters, advancedParameters)
const preSignTransaction = await sdk.getPreSignTransaction({ orderId, account: smartContractWalletAddress })
console.log('Order created with "pre-sign" state, id: ', orderId)
console.log('Execute the transaction to sign the order', preSignTransaction)
```


### postLimitOrder

This main difference between this function and `postSwapOrder` is that here you need to specify both sell and buy amounts.
Expand Down

0 comments on commit 31b1498

Please sign in to comment.