# 컨트랙 주소가 같을수 있나요?

**URL:** <https://devforum.kaia.io/t/topic/3516>\
**Category:** General / 미분류\
**Tags:** erc-721, smart-contract, klaytn\
**Created:** [1월 27, 2022, 9:52오전 UTC](https://devforum.kaia.io/t/topic/3516 "2022-01-27T09:52:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yong\_jung](https://yyz1.discourse-cdn.com/flex035/user_avatar/devforum.kaia.io/yong_jung/32/1050_2.png) [@yong\_jung](https://devforum.kaia.io/u/yong_jung)\
**Post date:** [1월 27, 2022, 9:52오전 UTC](https://devforum.kaia.io/t/topic/3516/1 "2022-01-27T09:52:38Z")

</div>

말이 안되긴하는데,  
테스트넷과, 메인넷에 같은 이름으로 NFT 컨트랙 발행했는데  
컨트랙 주소가 일치합니다. 가능한 일인가요 ?

---

<div class="post-metadata">

**Author:** ![Denver](https://yyz1.discourse-cdn.com/flex035/user_avatar/devforum.kaia.io/denver/32/557_2.png) [@Denver](https://devforum.kaia.io/u/Denver)\
**Post date:** [1월 28, 2022, 12:09오전 UTC](https://devforum.kaia.io/t/topic/3516/2 "2022-01-28T00:09:00Z")

</div>

@yong_jung  
동일한 주소와 동일한 Nonce로 배포하셨다면 같을 수 있습니다.  
해시라는 건 동일한 input에 대해 언제나 동일한 output이 나오기 때문이죠.

Contract를 배포할 때 어떤 함수가 호출되는지를 따라가보면 금방 이해하실 수 있습니다.  
Contract 계정을 생성할 때는 아래와 같이 EVM의 Create 메서드가 호출이 되고

```auto
// source link: https://github.com/klaytn/klaytn/blob/8f3b25f3d8afdc99d5a7441554051572f44f5bda/blockchain/vm/evm.go#L522-L527
// Create creates a new contract using code as deployment code.
func (evm *EVM) Create(caller types.ContractRef, code []byte, gas uint64, value *big.Int, codeFormat params.CodeFormat) (ret []byte, contractAddr common.Address, leftOverGas uint64, err error) {
	codeAndHash := &codeAndHash{code: code}
	contractAddr = crypto.CreateAddress(caller.Address(), evm.StateDB.GetNonce(caller.Address()))
	return evm.create(caller, codeAndHash, gas, value, contractAddr, false, codeFormat)
}

```

그 안에서 내부적으로 호출되는 CreateAddress를 보시면 Caller의 Address와 nonce를 RLP Encoding 하고 해당 값에 대해 Keccak256 해시를 구하는 것을 보실 수 있습니다.

```auto
// source link: https://github.com/klaytn/klaytn/blob/8f3b25f3d8afdc99d5a7441554051572f44f5bda/crypto/crypto.go#L87-L93
// CreateAddress creates a Klaytn address given the bytes and the nonce
func CreateAddress(b common.Address, nonce uint64) common.Address {
	data, _ := rlp.EncodeToBytes(struct {
		Addr common.Address
		Nonce uint64
	}{b, nonce})
	return common.BytesToAddress(Keccak256(data)[12:])
}

```

스펙 대로 정확히 동작한 것이고 스펙에 따라 같은 Contract 주소가 생성된 것입니다 🙂

감사합니다.

---

<div class="post-metadata">

**Author:** ![yong\_jung](https://yyz1.discourse-cdn.com/flex035/user_avatar/devforum.kaia.io/yong_jung/32/1050_2.png) [@yong\_jung](https://devforum.kaia.io/u/yong_jung)\
**Post date:** [1월 28, 2022, 7:05오전 UTC](https://devforum.kaia.io/t/topic/3516/3 "2022-01-28T07:05:43Z")

</div>

아 … nonce로 컨트랙 주소가 생성되는군요.  
둘다 첫번째 tx(nonce)가 컨트랙 생성이라 같았나봅니다.  
설명 감사드립니다!
