# create-crowdloan (/docs/tx/create-crowdloan)

Locks `deposit_tao` from the creator (it counts toward the raise and
comes back when the loan is dissolved) and opens the loan for
contributions until `end`. Provide exactly one of `target_ss58` (the
address that receives the raised funds on finalize) or `call` (an inner
intent, `{"op": ..., ...args}`, dispatched with the creator's origin on
finalize) — supplying both or neither is rejected. If the cap is reached
the creator finalizes with `finalize_crowdloan`. Passing `end` only
stops new contributions — nothing is refunded automatically: the creator
returns contributions with `refund_crowdloan` (contributors may also
`withdraw_crowdloan` themselves) and then `dissolve_crowdloan` to
recover the deposit.

| Signer    | Origin                                 | Pallet    | Wraps                                                              |
| --------- | -------------------------------------- | --------- | ------------------------------------------------------------------ |
| `coldkey` | signed account (pallet role may apply) | Crowdloan | [`Crowdloan.create`](/code/pallets/crowdloan/src/lib.rs#L331-L425) |

## Parameters [#parameters]

| Parameter              | Type              | Required | Description                                                                                                                                                    |
| ---------------------- | ----------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `deposit_tao`          | number \| `"all"` | yes      | Creator's initial deposit, locked when the crowdloan opens. It counts toward the raise and is returned when the crowdloan is dissolved.                        |
| `min_contribution_tao` | number \| `"all"` | yes      | Smallest contribution the crowdloan will accept from a contributor.                                                                                            |
| `cap_tao`              | number \| `"all"` | yes      | Maximum total to raise. Reaching the cap lets the creator finalize.                                                                                            |
| `end`                  | integer           | yes      | Block number at which the crowdloan stops accepting contributions. Passing it refunds nothing by itself; refunds happen via explicit refund or withdraw calls. |
| `target_ss58`          | string            | no       | Account that receives the raised funds on finalize. Provide exactly one of this or call.                                                                       |
| `call`                 | object            | no       | Inner intent dispatched with the creator's origin on finalize, as a JSON object \{"op": \<name>, ...args}. Provide exactly one of this or target\_ss58.        |

Address parameters (`--hotkey`, `--coldkey`, `--dest`, ...) accept a raw ss58
address, an address-book or proxy-book name, or a local wallet/hotkey name.

## CLI [#cli]

Preview with `--dry-run` (shows fee, effects, and policy result without
submitting), then submit:

```bash
btcli tx create-crowdloan \
  --deposit-tao <amount|all> \
  --min-contribution-tao <amount|all> \
  --cap-tao <amount|all> \
  --end <int> --dry-run
btcli tx create-crowdloan \
  --deposit-tao <amount|all> \
  --min-contribution-tao <amount|all> \
  --cap-tao <amount|all> \
  --end <int> -w my_coldkey
```

## Python [#python]

```python
import bittensor as bt
from bittensor.wallet import Wallet

wallet = Wallet(name="my_coldkey", hotkey="my_hotkey")
intent = bt.CreateCrowdloan(deposit_tao=1.0, min_contribution_tao=1.0, cap_tao=1.0, end=0)

sub = bt.Subtensor()
plan = sub.plan(intent, wallet)   # fee, effects, policy — no submission
result = sub.execute(intent, wallet)
if not result.success:
    print(result.error.code, result.error.remediation)
```

(`bt.Subtensor` is also the async client — `async with bt.Subtensor() as client:`
— see [The client](/docs/concepts/client).) Or build the intent by op name, as
an agent would:

```python
result = sub.execute_tool("create_crowdloan", {...}, wallet)
```

## On-chain implementation [#on-chain-implementation]

`Crowdloan.create` — [`pallets/crowdloan/src/lib.rs#L341`](/code/pallets/crowdloan/src/lib.rs#L331-L425):

```rust
        #[pallet::call_index(0)]
        #[pallet::weight({
			let di = call.as_ref().map(|c| c.get_dispatch_info());
			let inner_call_weight = match di {
				Some(di) => di.call_weight,
				None => Weight::zero(),
			};
			let base_weight = T::WeightInfo::create();
			(base_weight.saturating_add(inner_call_weight), Pays::Yes)
		})]
        pub fn create(
            origin: OriginFor<T>,
            #[pallet::compact] deposit: BalanceOf<T>,
            #[pallet::compact] min_contribution: BalanceOf<T>,
            #[pallet::compact] cap: BalanceOf<T>,
            #[pallet::compact] end: BlockNumberFor<T>,
            call: Option<Box<<T as Config>::RuntimeCall>>,
            target_address: Option<T::AccountId>,
        ) -> DispatchResult {
            let creator = ensure_signed(origin)?;
            let now = frame_system::Pallet::<T>::block_number();

            // Ensure the deposit is at least the minimum deposit, cap is greater than deposit
            // and the minimum contribution is greater than the absolute minimum contribution.
            ensure!(
                deposit >= T::MinimumDeposit::get(),
                Error::<T>::DepositTooLow
            );
            ensure!(cap > deposit, Error::<T>::CapTooLow);
            ensure!(
                min_contribution >= T::AbsoluteMinimumContribution::get(),
                Error::<T>::MinimumContributionTooLow
            );
            ensure!(
                call.is_some() != target_address.is_some(),
                Error::<T>::InvalidFinalizationConfig
            );

            Self::ensure_valid_end(now, end)?;

            // Ensure the creator has enough balance to pay the initial deposit
            ensure!(
                CurrencyOf::<T>::balance(&creator) >= deposit,
                Error::<T>::InsufficientBalance
            );

            let crowdloan_id = NextCrowdloanId::<T>::get();
            let next_crowdloan_id = crowdloan_id.checked_add(1).ok_or(Error::<T>::Overflow)?;
            NextCrowdloanId::<T>::put(next_crowdloan_id);

            // Derive the funds account and keep track of it
            let funds_account = Self::funds_account(crowdloan_id);
            frame_system::Pallet::<T>::inc_providers(&funds_account);

            // If the call is provided, bound it and store it in the preimage storage
            let call = if let Some(call) = call {
                Some(T::Preimages::bound(*call)?)
            } else {
                None
            };

            let crowdloan = CrowdloanInfo {
                creator: creator.clone(),
                deposit,
                min_contribution,
                end,
                cap,
                funds_account,
                raised: deposit,
                target_address,
                call,
                finalized: false,
                contributors_count: 1,
            };
            Crowdloans::<T>::insert(crowdloan_id, &crowdloan);

            // Transfer the deposit to the funds account
            CurrencyOf::<T>::transfer(
                &creator,
                &crowdloan.funds_account,
                deposit,
                Preservation::Expendable,
            )?;

            Contributions::<T>::insert(crowdloan_id, &creator, deposit);

            Self::deposit_event(Event::<T>::Created {
                crowdloan_id,
                creator,
                end,
                cap,
            });

            Ok(())
        }
```

Every file is browsable under [/code](/code) exactly as built into the runtime, or as plain text under `/code/raw/<path>` (index: [`/code/index.json`](/code/index.json)).
