Dynamic Contract Creation (Clones) - Binance Smart Chain


I have a factory contract that does deploy other contract on the fly . The following piece of code works perfectly on ganache/ethereum but on BSC, it creates just an empty wallet.

function createClone(address target) internal returns (address payable result) {
    bytes20 targetBytes = bytes20(target);
    assembly {
        let clone := mload(0x40)
        mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
        mstore(add(clone, 0x14), targetBytes)
        mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
        result := create(0, clone, 0x37)
/// here is the sample usage
// templateAddr is the source contract to clone 
address payable lo = createClone(templateAddr);
MyContract(lo).initialize(); // initialize

Can somebody please point me to the right direction? Any idea why it isn’t working on BSC.

// this is the EIP

I am trying this piece of code on binance smart chain (TESTNET)

Thank you,

1 Like

Hi @fma,

Welcome to the community :wave:

You could try using the Clones library in OpenZeppelin Contracts:

We recently ran a workshop on using Clones. See the recap:

I am not aware of why there would be issues on Binance Smart Chain creating clones (minimal proxies).

Thank you very much for the response.

I tried the clones family from the OpenZeppelin contracts and still the same, on ETH minimal proxies are created but on BSC testnet it always create a wallet, I am really not sure why is it happening, if I would have some funds will try it on the BSC mainnet and let you know the results.

Can’t figure out what is going wrong here.


1 Like

Hi @fma,

I suggest looking at the code from the workshop (https://blog.openzeppelin.com/workshop-recap-cheap-contract-deployment-through-clones/). One of the team just deployed using the Clones library to Binance Smart Chain testnet.

I actually got the issue. The bsc scanner is having problem displaying the minimal proxies - it rather shows it as a WALLET.

If I access the same contract through truffle it works fine.


1 Like

Hi @fma,

Glad to hear that you resolved.

I suggest reporting this issue to the BSCscan team so that if it is a bug that they can look at resolving.