Factory
A factory is a smart contract that stores a compiled contract on itself, and automatizes deploying it into sub-accounts.
We have two factory examples:
- Token Factory: A factory that creates fungible tokens contracts.
- A Generic Factory: A factory that creates donation contracts, but allows to change the contract it deploys.
info
In this page we will focus on the Donation factory, to learn more about the token factory visit its repository.
Generic Factory​
The Generic Factory presents a contract factory that:
- Creates sub-accounts of itself and deploys its contract on them (
create_factory_subaccount_and_deploy). - Can change the stored contract using the
update_stored_contractmethod.
- 🦀 Rust
- deploy.rs
- manager.rs
Loading...
Loading...
Quickstart​
Build and Deploy the Factory​
You can automatically compile and deploy the contract in the NEAR testnet by running:
./deploy.sh
Once finished, check the neardev/dev-account file to find the address in which the contract was deployed:
cat ./neardev/dev-account
# e.g. dev-1659899566943-21539992274727
Deploy the Stored Contract Into a Sub-Account​
create_factory_subaccount_and_deploy will create a sub-account of the factory and deploy the
stored contract on it.
near call <factory-account> create_factory_subaccount_and_deploy '{ "name": "sub", "beneficiary": "<account-to-be-beneficiary>"}' --deposit 1.24 --accountId <account-id> --gas 300000000000000
This will create the sub.<factory-account>, which will have a donation contract deployed on it:
near view sub.<factory-account> get_beneficiary
# expected response is: <account-to-be-beneficiary>