SDK 常见
测试覆盖率
| 发言 | 分支 | 职能 | 行数 |
|---|---|---|---|
这个包是核心CoW协议SDK的一部分. 它没有显著的独立功能,而是提供所有SDK软件包共享的重要类型,接口和公用设备的接入.
包括什么
- 抽象提供者适配器 - 区块链相互作用的基本类别
- 共享类型 - 整个SDK通用接口和类型
- 公用事业 - 辅助功能和公用设施
- 全球背景 - 软件包之间共享适配器上下文
安装
npm install @cowprotocol/sdk-common
使用量
import {
AbstractProviderAdapter,
AdapterTypes,
Block,
TransactionParams,
PrivateKey,
CowError,
GenericContract,
setGlobalAdapter,
} from '@cowprotocol/sdk-common'
import { ViemAdapter } from '@cowprotocol/sdk-viem-adapter'
import { createPublicClient, http, privateKeyToAccount } from 'viem'
import { sepolia } from 'viem/chains'
// Create and configure adapter
// There are EthersV5Adapter and EthersV6Adapter as well
// @cowprotocol/sdk-ethers-v5-adapter, @cowprotocol/sdk-ethers-v6-adapter
const adapter = new ViemAdapter({
provider: createPublicClient({
chain: sepolia,
transport: http('YOUR_RPC_URL')
}),
// You also can set `walletClient` instead of `signer` using `useWalletClient` from wagmi
signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
})
// Set up global adapter
setGlobalAdapter(adapter)
// Use shared types and utilities
const txParams: TransactionParams = {
to: '0x...',
data: '0x...',
value: '0',
}
使用 CoW SDK 软件
在使用COW SDK时,这些通用的公用设施自动可用:
import {
CowSdk,
AbstractProviderAdapter,
AdapterTypes,
Block,
TransactionParams,
PrivateKey,
CowError,
GenericContract,
} from '@cowprotocol/cow-sdk'
说明: 这个软件包主要被设计为其他SDK软件包的依赖性,而不是直接被终端用户所使用. 大多数开发者应该使用
@cowprotocol/cow-sdk软件包或特定特性软件包@cowprotocol/sdk-trading。 。 。 .