The main features of UTXO-based transactions are:

  • Transactions on a UTXO-based blockchain consist of inputs and outputs. Each input refers to a specific UTXO (unspent transaction output) from a previous transaction. When you create a new transaction, you use one or more UTXOs as inputs, and you can specify different destination addresses (i.e., the ‘to’ address) for the outputs.
  • When you spend a fraction of a UTXO, the remaining amount needs to be sent back to you. This is typically done by including one of your own addresses as a “change address” in the transaction. This change address receives the remaining funds that are not sent to the destination addresses.

In Custodial Wallets, transactions are initiated based on all available Unspent Transaction Outputs (UTXOs) within each wallet. Cobo will manage the corresponding logics and you are not required to construct an input address.

For MPC Wallets, you have the flexibility to decide whether to initiate a transaction using all available UTXOs under each wallet or under a specified address. Additionally, you can define a change address. If none is specified, the system will automatically send the change to the ‘from’ address. In cases where the transaction originates directly from the wallet rather than a ‘from’ address, any change will be sent back to the default address of the wallet (i.e., the address that was auto generated when you first created the MPC Wallet).

Code Samples for MPC Wallets

If the transaction is initiated using all available UTXOs under an MPC Wallet:

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

signer = LocalSigner("your_api_secret_here")
mpc_client = MPCClient(signer=signer, env=DEVELOP_ENV, debug=True)
response = mpc_client.create_transaction(
   coin="XTN",
   request_id=f"MPCTransaction-{int(time.time() * 1000)}",
   amount=None,
   to_address_details='[{"to_address": "2N4J1WajwKZKpRtzzUmaW9B5GEqkppqdVY9","amount": "547"},'
                       '{"to_address": "tb1qycxy8d8jgff8hql09y62smw5s5mrf3ryn2j9lk","amount": "548"}]',
   fee=10.1
)
print(response.result)

If the transaction is initiated using all available UTXOs under a designated address:

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

signer = LocalSigner("your_api_secret_here")
mpc_client = MPCClient(signer=signer, env=DEVELOP_ENV, debug=True)

response = mpc_client.create_transaction(
   coin="XTN",
   request_id=f"MPCTransaction-{int(time.time() * 1000)}",
   amount="10000",
   from_addr="tb1qtxkz0v063lgu0crqqnc2llarfg27lkyqq5l4mv",
   to_addr="tb1q0dr4tfw8eguswrpc2rrc5mg6af0k42jhu7rgyg",
)
print(response.result)

Code Samples for Custodial Wallets

The transaction is initiated using all UTXOs under a Custodial Wallet:

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 = "BTC"  # your target chain
coin_code = "BTC"  # your target coin
amount = 1000  # 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}")