# Using proxies created with ProxyFactory

**URL:** <https://forum.openzeppelin.com/t/using-proxies-created-with-proxyfactory/3411>\
**Category:** SDK\
**Created:** [July 27, 2020, 10:30am UTC](https://forum.openzeppelin.com/t/using-proxies-created-with-proxyfactory/3411 "2020-07-27T10:30:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kallolborah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/kallolborah/32/3684_2.png) [@kallolborah](https://forum.openzeppelin.com/u/kallolborah)\
**Post date:** [July 27, 2020, 10:30am UTC](https://forum.openzeppelin.com/t/using-proxies-created-with-proxyfactory/3411/1 "2020-07-27T10:30:06Z")

</div>

Hi  
I am trying to get some clarity on how proxies we create with ProxyFactory can be used/called.

My use case :

1. I have a implementation/logic contract called Cash.sol. This is Initializable, Ownable. The Cash contract should be able to generate cash tokens of multiple currencies when ether is paid in. So, a minimal proxy of the Cash contract we deploy for USD should be able to generate a USD token, and a minimal proxy of the Cash contract we deploy for EUR should be able to generate a EUR token, and so forth. The only things that are parametrized for the minimal proxies is therefore a ‘currency name’.

```auto
        //initiliaze proxies. here, _owner is the Factory, name is the currency name/symbol
        function initialize(bytes32 _name, address _owner) public {
            Ownable.initialize(_owner);
            factory = Factory(_owner);
            name = _name;
            symbol = _name;
        }

```

1. I have a Factory.sol which is a ProxyFactory. It creates proxies of the Cash (implementation) contract and stores the proxy addresses in an array.

```auto
            function createToken(address _target, bytes32 tokenName, bytes32 tokenType) external{
                    address _owner = msg.sender;            
                    bytes memory _payload = abi.encodeWithSignature("initialize(bytes32,address)", tokenName, _owner);

                    // Deploy proxy
                    address _via = deployMinimal(_target, _payload);
                    emit TokenCreated(_via, tokenName, tokenType);
                    if(tokenType == "Cash"){
                            token[_via] = via("ViaCash", tokenName);
                            tokens.push(_via);
                    }
            }

```

1. I deploy the Factory and call and parameterize createToken() in the Factory with any number and names of currencies I want to support.

```auto
        deployer.deploy(Factory).then(async () => {
                const factory = await Factory.new();
                const cash = await Cash.new(); 
                await factory.createToken(cash.address, web3.utils.utf8ToHex("USD"), 
                web3.utils.utf8ToHex("Cash")); await factory.createToken(cash.address, 
                web3.utils.utf8ToHex("EUR"), web3.utils.utf8ToHex("Cash"));});

```

Now, my rather (naive) question 🙂 is - to use the proxies, do I obtain the cash proxy address stored in the Factory and then use that address to send ether to ? I do not see how calls are delegated to the proxies.

Thanks !

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [July 28, 2020, 4:24am UTC](https://forum.openzeppelin.com/t/using-proxies-created-with-proxyfactory/3411/2 "2020-07-28T04:24:40Z")

</div>

Hi @kallolborah,

Welcome to the community 👋

> [@kallolborah](#):
>
> to use the proxies, do I obtain the cash proxy address stored in the Factory and then use that address to send ether to

That is correct. You call functions using the ABI of the Cash contract and the address of the minimal proxy.

The _minimal proxy_ is a simple contract that just _delegates_ all calls to a logic contract. A _delegate call_ is similar to a regular call, except that all code is executed in the context of the caller, not of the callee. Meaning that the state is with the _minimal proxy_ and there can be multiple _minimal proxies_ all pointing to the one logic contract.

I suggest reading (if you haven’t already): [Deep dive into the Minimal Proxy contract](https://forum.openzeppelin.com/t/deep-dive-into-the-minimal-proxy-contract/1928)

---

<div class="post-metadata">

**Author:** ![xxs](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/xxs/32/2767_2.png) [@xxs](https://forum.openzeppelin.com/u/xxs)\
**Post date:** [July 28, 2020, 7:19am UTC](https://forum.openzeppelin.com/t/using-proxies-created-with-proxyfactory/3411/3 "2020-07-28T07:19:11Z")

</div>

> That is correct. You call functions using the ABI of the Cash contract and the address of the minimal proxy.

If I want to call functions of one token that created by the Factory and the Cash, should I use the ABI of the Cash contract and its address that created by the deployMinimal() of the Factory, instead of the address of the minimal proxy?

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [July 28, 2020, 7:32am UTC](https://forum.openzeppelin.com/t/using-proxies-created-with-proxyfactory/3411/4 "2020-07-28T07:32:33Z")

</div>

Hi @xxs,

Welcome to the community 👋

We need to call the contract using the address of the minimal proxy, this is returned by [`deployMinimal`](https://docs.openzeppelin.com/upgrades/2.8/api#ProxyFactory-deployMinimal-address-bytes-) and in the example contract above is emitted in the `TokenCreated` event.

---

<div class="post-metadata">

**Author:** ![xxs](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/xxs/32/2767_2.png) [@xxs](https://forum.openzeppelin.com/u/xxs)\
**Post date:** [July 28, 2020, 7:40am UTC](https://forum.openzeppelin.com/t/using-proxies-created-with-proxyfactory/3411/5 "2020-07-28T07:40:25Z")

</div>

Thanks. So if I want to deploy the 6 instance contracts that created by the Factory and the Cash, using Truffle, here is my part code in my migration.js (continued the third point above):

```javascript
for (let i=0; i<6; i++) {
           var factoryTokenAddress = await factory.tokens(i);
           var cashInstance = await Cash.at(factoryTokenAddress); 
           console.log(factoryTokenAddress);
           console.log(await factory.token(factoryTokenAddress));
        }

```

It correct and can work? Thanks.

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [July 28, 2020, 7:47am UTC](https://forum.openzeppelin.com/t/using-proxies-created-with-proxyfactory/3411/6 "2020-07-28T07:47:16Z")

</div>

Hi @xxs,

I would be tempted to have it in a separate script that you run after deployment of the factory and the logic contract. Otherwise it appears to look ok. I suggest testing it out on a local blockchain.

---

<div class="post-metadata">

**Author:** ![xxs](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/xxs/32/2767_2.png) [@xxs](https://forum.openzeppelin.com/u/xxs)\
**Post date:** [July 30, 2020, 9:54am UTC](https://forum.openzeppelin.com/t/using-proxies-created-with-proxyfactory/3411/7 "2020-07-30T09:54:07Z")

</div>

Hi @abcoathup

```javascript
deployer.deploy(Factory).then(async () => {
                const factory = await Factory.new();
                const cash = await Cash.new(); 
                await factory.createToken(cash.address, web3.utils.utf8ToHex("USD"), 
                web3.utils.utf8ToHex("Cash")); await factory.createToken(cash.address, 
                web3.utils.utf8ToHex("EUR"), web3.utils.utf8ToHex("Cash"));});

```

Here are 2 cash proxy contracts now, and they are created. But if they are deployed now?
