即刻安装 Cobo WaaS Skill,在 Claude Code、Cursor 等 AI 开发环境中使用自然语言集成 WaaS API,显著提升开发效率 🚀
使用 MPC 钱包作为委托人
假设您在 Base 链上有一个 Safe,并在 Stargate 协议中存入了 ETH 进行收益农业。您可以使用 MPC 钱包通过 WaaS API 执行自动化、定期的奖励收集。- 在开始之前,请参考 智能合约钱包入门 完成初始设置,包括安装 WaaS SDK 和将 Safe 导入 Cobo Portal。
-
配置链上风险控制策略,以自动批准通过 MPC 钱包地址发起的领取方法。
- 选择 MPC 钱包地址作为委托人。
- 将 条件 设置为 自定义合约调用。
- 选择 方法级别。
- 输入 Stargate 抵押合约的地址作为目标合约,并选择 claim 作为方法。
- 点击 提交 以发起多签交易。请求 Safe 签名人确认。

- 执行以下代码以每天上午 9 点领取奖励。示例代码使用 调用智能合约 操作与 Stargate 合约交互。
Python 示例代码
Python 示例代码
Report incorrect code
Copy
Ask AI
import schedule
import time
from web3 import Web3
import cobo_waas2
# 指定 Stargate 合约地址
STG_CLAIM_CONTRACT = "0xdfc47dcef7e8f9ab19a1b8af3eecf000c7ea0b80"
# 从 Etherscan 获取 ABI
STG_CLAIM_ABI = []
# 指定 Stargate 池地址
STG_ETH_POOL = "0x98fB8522d891F43B771e2d27367b41Ba138D0B80"
w3 = Web3(Web3.HTTPProvider("<RPC_URL>"))
contract = w3.eth.contract(address=STG_CLAIM_CONTRACT, abi=STG_CLAIM_ABI)
data = contract.encodeABI("claim", [[STG_ETH_POOL]])
def get_delegate(wallet_id, request: cobo_waas2.SafeWalletDelegates):
# Enter a context with an instance of the API client
with cobo_waas2.ApiClient(configuration) as api_client:
# Create an instance of the API class
wallet_api_instance = cobo_waas2.WalletsSmartContractWalletsApi(api_client)
try:
# Call the List Delegates operation to retrieve available Delegates
api_response = wallet_api_instance.list_safe_wallet_delegates(
wallet_id=wallet_id,
safe_wallet_delegates=request
)
if not api_response:
raise Exception("No delegate found")
print("The response of WalletsApi->list_safe_wallet_delegates:")
print(json.dumps(api_response[0].to_dict(), indent=2))
return api_response[0]
except Exception as e:
print("Exception when calling WalletsApi: %s\n", e)
def get_wallet(wallet_id) -> cobo_waas2.SafeWallet:
with cobo_waas2.ApiClient(configuration) as api_client:
# Create an instance of the API class
wallet_api_instance = cobo_waas2.WalletsApi(api_client)
try:
# Call the Get wallet information operation to retrieve the wallet information, including the wallet address
api_response = wallet_api_instance.get_wallet_by_id(
wallet_id=wallet_id
)
print("The response of WalletsApi->get_wallet_by_id:")
print(json.dumps(api_response.to_dict(), indent=2))
return api_response.actual_instance.actual_instance
except Exception as e:
print("Exception when calling WalletsApi: %s\n", e)
def contract_call(wallet_id, contract_address, data, value):
contract_call_request = cobo_waas2.SafeWalletDelegates(
actual_instance=cobo_waas2.SafeWalletDelegatesContractCall(
request_type=cobo_waas2.EstimateFeeRequestType.CONTRACTCALL,
address=contract_address,
calldata=data,
value=value,
)
)
delegate = get_delegate(wallet_id, contract_call_request)
wallet = get_wallet(wallet_id)
with cobo_waas2.ApiClient(configuration) as api_client:
wallet_api_instance = cobo_waas2.TransactionsApi(api_client)
try:
# Use the Call smart contract operation to interact with the Stargate contract
api_response = wallet_api_instance.create_contract_call_transaction(
cobo_waas2.ContractCallParams(
request_id=str(uuid.uuid4()),
chain_id=wallet.chain_id,
source=cobo_waas2.ContractCallSource(
actual_instance=cobo_waas2.SafeContractCallSource(
source_type=cobo_waas2.ContractCallSourceType.SAFE_WALLET,
wallet_id=wallet_id,
address=wallet.safe_address,
delegate=delegate,
)
),
destination=cobo_waas2.ContractCallDestination(
actual_instance=cobo_waas2.EvmContractCallDestination(
destination_type=cobo_waas2.ContractCallDestinationType.EVM_CONTRACT,
address=contract_address,
calldata=data,
value=value,
),
),
category_names=["<CATEGORY_NAME>"],
description="<DESCRIPTION>",
)
)
print("The response of TransactionsApi->create_contract_call_transaction:")
print(json.dumps(api_response.to_dict(), indent=2))
except Exception as e:
print("Exception when calling TransactionsApi: %s\n", e)
def daily_contract_call():
print("claim stargate")
contract_call(
wallet_id=wallet_id,
contract_address=STG_CLAIM_CONTRACT,
data=data,
value="0",
)
# Schedule the contract call to run every day at 9:00 a.m.
schedule.every().day.at("09:00").do(daily_contract_call)
# Keep the script running
while True:
schedule.run_pending()
time.sleep(1)
使用外部 EOA 钱包作为委托人
您也可以使用外部 EOA 钱包来领取奖励。初始步骤与 [MPC 钱包](#使用 MPC 钱包作为委托人) 相似,但您需要将 EOA 钱包地址设置为委托人,并相应地调整链上风险控制策略。 与使用 WaaS API 不同,EOA 钱包通过使用 Cobo Safe 提供的函数与 Safe 交互。该过程可以概述如下:- 构建领取交易以从 Stargate 收集 Farming 奖励。
- 将领取交易封装在 Cobo Safe 交易中。
- 通过 EOA 钱包发起 Cobo Safe 交易。
- 使用 EOA 钱包签署交易并发送到网络。
Python 示例代码
Python 示例代码
Report incorrect code
Copy
Ask AI
import json
from web3 import Web3
import cobo_waas2
import os
from eth_account import Account
# 从环境变量获取私钥
PRIVATE_KEY = os.getenv('ETH_PRIVATE_KEY')
# 创建账户对象
account = Account.from_key(PRIVATE_KEY)
w3 = Web3(Web3.HTTPProvider("<RPC_URL>"))
def get_wallet(wallet_id) -> cobo_waas2.SafeWallet:
with cobo_waas2.ApiClient(configuration) as api_client:
# Create an instance of the API class
wallet_api_instance = cobo_waas2.WalletsApi(api_client)
try:
# Call the Get wallet information operation to retrieve the wallet information, including the wallet address
api_response = wallet_api_instance.get_wallet_by_id(
wallet_id=wallet_id
)
print("The response of WalletsApi->get_wallet_by_id:")
print(json.dumps(api_response.to_dict(), indent=2))
return api_response.actual_instance.actual_instance
except Exception as e:
print("Exception when calling WalletsApi: %s\n", e)
# 输入钱包 ID,位于 Cobo Portal 中
wallet = get_wallet("<YOUR_WALLET_ID>")
# 获取 Cobo Safe 地址
cobo_safe_address = wallet.cobo_safe_address
# 从 Etherscan 获取 ABI
COBO_SAFE_ABI = []
# 指定 Stargate 合约地址
STG_CLAIM_CONTRACT = "0xdfc47dcef7e8f9ab19a1b8af3eecf000c7ea0b80"
# 从 Etherscan 获取 ABI
STG_CLAIM_ABI = []
STG_ETH_POOL = "0x98fB8522d891F43B771e2d27367b41Ba138D0B80"
stg_contract = w3.eth.contract(address=STG_CLAIM_CONTRACT, abi=STG_CLAIM_ABI)
# 构建 Stargate 领取交易
data = stg_contract.encodeABI("claim", [[STG_ETH_POOL]])
# 构建 Cobo Safe 交易
cobo_safe_contract = w3.eth.contract(address=cobo_safe_address, abi=COBO_SAFE_ABI)
call_datas = [
[
0,
Web3.to_checksum_address(STARGATE_STAKING),
0,
Web3.to_bytes(hexstr=data),
b"",
b"",
]
]
# 构建 EOA 钱包交易。该交易通过 EOA 账户发起 Cobo Safe 交易。
transaction = cobo_safe_contract.functions.execTransactions(call_datas).build_transaction({
'from': account.address,
'nonce': w3.eth.get_transaction_count(account.address),
# 设置 gas 费用限制
'gas': 200000,
'gasPrice': w3.eth.gas_price,
})
# 签署交易
signed_tx = account.sign_transaction(transaction)
# 发送交易
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print(f"Transaction sent with hash: {tx_hash.hex()}")
