0

Hi i needed to make our ERC20 token crosschain but in process something went wrong and it is deployed on different blockchain with completely different address from other blockchains that is previously deployed. I am not sure if i is possible to do another deployment with same wallet credentials(or is it?), i wanted to see if is it possible to make it cross chain after deployment ? Now i know for moving tokens from one blockchain to another with bridges and atomic swaps but is it the same as being cross chain? If it possible something of above can you tell me in witch direction to start?

2 Answers 2

0

I assume your asking if it's possible to re-deploy the token at the same address being deployed to on other chains.

I think based on what you mention it is not possible, because a contract address is determined based on two factors: The nonce of the sender, and its address. The nonce being how many transactions has been made from the address.

So I assume why the token contract was not created at the same address that you have in other chains is because of nonce inconsistency.

What you can do is to re-deploy the contract with the same nonce from the same address at different blockchains to reproduce the same address. But as I told you, your problem can't be fixed if you missed the nonce that produces the specific address of the token.

You can get the nonce with getTransactionCount in web3.js

0

You can deploy deterministic smart contract to different chain using factory method. In this you can apply same salt to deploy a deterministic smart contract using Factory approach. You can know the contract address before you deploy it. If you want to deploy same contract in same blockchain then you have to destroy the contract but you can deploy in different blockchain (EVM based) the same contract using Factory method and salt. In this case Factory will be the deployer of the contract, you can tweak the smart contract to make your wallet owner of the contract easily.

A simple example code:

//SPDX-License-Identifier: None

pragma solidity ^ 0.8.7;


contract Factory {
    address public owner;
    uint _salt = 1234;

    address public autoCode;
    bool public paid;

    receive() payable external {
        autoCode = address(0);
        unchecked {
            deploy();
        }
        paid = true;
    }

    constructor() {
        owner = msg.sender;
    }

    function deploy() public {
        paid = false;
        if(address(this).balance > 0)
            payable(owner).transfer(address(this).balance);
        autoCode = address(new AutoCode{salt: bytes32(_salt)}());
        require(autoCode == getAddress());
    }

    function getBytecode() public pure returns (bytes memory) {
        bytes memory bytecode = type(AutoCode).creationCode;
        return abi.encodePacked(bytecode);
    }
    
    function getAddress() public view returns (address){
        bytes32 hash = keccak256(
            abi.encodePacked(bytes1(0xff), 
            address(this),
            bytes32(_salt), 
            keccak256(getBytecode())));
        return address(uint160(uint256(hash)));
    }
}

contract AutoCode {

    address public owner;

    receive() payable external {
        destroy();
    }

    constructor() {
        owner = msg.sender;
    }

    function destroy() public {
        selfdestruct(payable(owner));
    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.