# Nonce of a smart contract when transaction reverts

**URL:** https://forum.openzeppelin.com/t/nonce-of-a-smart-contract-when-transaction-reverts/3418
**Category:** Contracts
**Created:** [July 28, 2020, 2:40am UTC](https://forum.openzeppelin.com/t/nonce-of-a-smart-contract-when-transaction-reverts/3418 "2020-07-28T02:40:26Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![weili](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/weili/32/2766_2.png) [@weili](https://forum.openzeppelin.com/u/weili)
#### Post date: [July 28, 2020, 2:40am UTC](https://forum.openzeppelin.com/t/nonce-of-a-smart-contract-when-transaction-reverts/3418/1 "2020-07-28T02:40:26Z")

</div>

When I red the below, I have a question about “CREATE”,

[https://docs.openzeppelin.com/cli/2.8/deploying-with-create2](https://docs.openzeppelin.com/cli/2.8/deploying-with-create2)

[for regular accounts it is increased on every transaction, while for contract accounts it is increased on every contract creation]

When a transaction from EOA to call a smart contract’s “new contract”, if the transaction was roll backed, The transaction’s Nonce will count up, what about the Nonce of the smart contract?  
Will the smart contract’s Nonce count up?

---

<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: [August 4, 2020, 8:39am UTC](https://forum.openzeppelin.com/t/nonce-of-a-smart-contract-when-transaction-reverts/3418/2 "2020-08-04T08:39:02Z")

</div>

Hi @weili,

Welcome to the community forum 👋.

Thanks for posting here.

I couldn’t find any documentation on what happens, so I tried it locally and when a contract factory creates a contract that reverts on creation, then the transaction count of the contract factory does not increment. The contract factory transaction count increments when a contract is successfully created.

The same happens when a proxy contract is created using Create2 and initialized, the transaction count is incremented. When a proxy contract is created using Create2 and initialization reverts, the transaction count does not increment.

I used the following contracts and obtained the following results:

## MyFactory.sol

```auto
pragma solidity ^0.5.0;

import "@openzeppelin/upgrades/contracts/upgradeability/ProxyFactory.sol";
import "./MyContract.sol";
import "./MyContractRevert.sol";

contract MyFactory is ProxyFactory {

    function deployMyContract() public {
        new MyContract();
    }

    function deployMyContractRevert() public {
        new MyContractRevert();
    }

    function deploy(uint256 salt, address logic, address admin, bool init) public returns (address) {
        bytes memory payload = abi.encodeWithSignature("initialize(bool)", init);
        deploy(salt, logic, admin, payload);
    }
}

```

## MyContract.sol

```auto
pragma solidity ^0.5.0;

contract MyContract {
    function initialize(bool init) public {
        require(init, "MyContract: false");
    }
}

```

## MyContractRevert.sol

```auto
pragma solidity ^0.5.0;

contract MyContractRevert {
    constructor() public {
        require(false, "MyContractRevert: false");
    }
}

```

## Setup

```auto
truffle(develop)> factory = await MyFactory.new()
truffle(develop)> myContract = await MyContract.new()
truffle(develop)> web3.eth.getTransactionCount(factory.address)
1

```

## Factory creates a contract

```auto
truffle(develop)> await factory.deployMyContract()
{ tx: ...
truffle(develop)> web3.eth.getTransactionCount(factory.address)
2

```

## Factory reverts creating a contract

```auto
> await factory.deployMyContractRevert()
Thrown:
{ Error: Returned error: VM Exception while processing transaction: revert MyContractRevert: false -- Reason given: MyContractRevert: false.
truffle(develop)> web3.eth.getTransactionCount(factory.address)
2

```

## Factory creates a proxy contract using Create2 and initializes it

```auto
truffle(develop)> await factory.deploy(0, myContract.address, accounts[0], true)
{ tx:...
truffle(develop)> web3.eth.getTransactionCount(factory.address)
3

```

## Factory creates a proxy contract using Create2 and initialize reverts

```auto
truffle(develop)> await factory.deploy(1, myContract.address, accounts[0], false)
Thrown:
{ Error: Returned error: VM Exception while processing transaction: revert
truffle(develop)> web3.eth.getTransactionCount(factory.address)
3

```

---

<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: [August 9, 2020, 11:39pm UTC](https://forum.openzeppelin.com/t/nonce-of-a-smart-contract-when-transaction-reverts/3418/3 "2020-08-09T23:39:16Z")

</div>

Hi @weili,

Just wanted to followup to see if you had tried this yourself or had further questions?
