Withdraw transactions in MPC Wallets and Custodial Wallets follow distinct creation processes via APIs. In MPC Wallets, kindly take note of the distinctions between transactions created on Account-based blockchains and those on UTXO-based blockchains.

Code Samples for MPC Wallets

The following code samples focus on Account-based blockchains. For information on how to create a transaction on UTXO-based blockchains, please refer to this guide.

The following codes demonstrate the transfer of 0.1 ETH to a specified receiving address via Account-based blockchains.

from cobo_custody.client.mpc_client import MPCClient
from cobo_custody.config import DEVELOP_ENV
from cobo_custody.signer.local_signer import LocalSigner
import time

api_secret = "your api secret"  # your wallet api secret
chain_code = "ETH"  # your target chain
coin_code = "ETH"  # your target coin
amount = "100000000000000000"  # withdraw amount:0.01ETH
from_address = "your mpc wallet address"  # your mpc wallet address
to_address = "your address"  # your address

# init cobo client
mpc_client = MPCClient(signer=LocalSigner(api_secret), env=DEVELOP_ENV, debug=False)

request_id = f"MPCTransaction-{int(time.time() * 1000)}"  # your custom request_id
response = mpc_client.create_transaction(
   coin=coin_code,
   request_id=request_id,
   amount=amount,
   from_addr=from_address,
   to_addr=to_address,
   gas_price=6500000000,
   gas_limit=21000,
)
print(f"Withdraw: {response.result}")

For more information on the “mpc_create_transaction” endpoint, click here.

Code Samples for Custodial Wallets

In Custodial Wallets, an on-chain transaction will be triggered if the receiving address is an external address. Conversely, if the receiving address belongs to a Custodial Wallet managed by Cobo, the transaction will be executed off-chain without incurring any gas fees.

from cobo_custody.client import Client
from cobo_custody.config import DEVELOP_ENV
from cobo_custody.signer.local_signer import LocalSigner
import time

api_secret = "your_api_secret"  # your wallet api secret
chain_code = "ETH"  # your target chain
coin_code = "ETH"  # your target coin
amount = 100000000000000000  # withdraw amount
to_address = "your address"  # your address

# init cobo client
client = Client(signer=LocalSigner(api_secret), env=DEVELOP_ENV, debug=False)

request_id = f"ApiTransaction-{int(time.time() * 1000)}"    # your custom request_id
response = client.withdraw(
   coin=coin_code,
   request_id=request_id,
   amount=amount,
   address=to_address,
)
print(f"Withdraw: {response.result}")

For more information on the “new_withdraw_request” endpoint, click here.