Connecting the OpenZeppelin CLI to an Azure PoA Network

I would guess that this is documented somewhere but I can’t find it.

I want to deploy my contracts to my Azure PoA blockchain.

MetaMask sees my Azure PoA Blockchain just fine.

When I try an “oz create openzeppelin-eth/StandaloneERC20” in the CLI, my Azure blockchain is not in the networks list.

I’m guessing that I have to play with my networks.json – but it is not entirely clear how.

TIA!

Mark

1 Like

OK. I’ve made some progress.

Here’s the two different attempts I’ve added to my network.js file

azure: {
      provider: () => new HDWalletProvider(metamask_mnemonic, rpc_endpoint),
      network_id: 103098097,
      gasPrice : 0
    },
    bad: {
      host: "etht5zt7j-dns-reg1.eastus2.cloudapp.azure.com", 
      port: 8540,
      network_id: 103098097, 
      // optional config values:
      // gas
      gasPrice: 0,
      // from - default address to use for any transaction Truffle makes during migrations
      // provider - web3 provider instance Truffle should use to talk to the Ethereum network.
      //          - function that returns a web3 provider instance (see below.)
      //          - if specified, host and port are ignored.
      skipDryRun: true // - true if you don't want to test run the migration locally before the actual migration (default is false)
      // timeoutBlocks: - if a transaction is not mined, keep waiting for this number of blocks (default is 50)
    },

First one just returns to a command prompt:

$ oz create 
Nothing to compile, all contracts are up to date. 
? Pick a contract to instantiate openzeppelin-eth/StandaloneERC20 
? Pick a network azure 
$

Second one wants to install dependencies and then hangs doing so . . . .

 oz create
Nothing to compile, all contracts are up to date.
? Pick a contract to instantiate openzeppelin-eth/StandaloneERC20
? Pick a network bad
? One or more linked dependencies are not yet deployed on dev-103098097.
Do you want to deploy them now? Yes
⠦ Deploying openzeppelin-eth dependency to network dev-103098097
⠦ Deploying @openzeppelin/contracts-ethereum-package dependency to network dev-103098097

I’ve tried the latter with and without the gasprice, from and skipdryrun arguments.

Any help?

1 Like

I believe that everything except the network is correct because it deploys fine to development.

$ oz create
Nothing to compile, all contracts are up to date.
? Pick a contract to instantiate openzeppelin-eth/StandaloneERC20
? Pick a network development
All implementations are up to date
? Call a function to initialize the instance after creating it? Yes
? Select which function * initialize(name: string, symbol: string, decimals: uint8)
? name: string: Play Token
? symbol: string: PLAY
? decimals: uint8: 2
✓ Instance created at 0xaD888d0Ade988EbEe74B8D4F39BF29a8d0fe8A8D
0xaD888d0Ade988EbEe74B8D4F39BF29a8d0fe8A8D
$
1 Like

Hi @MWaser,

The following documentation is on connecting to a public test network using OpenZeppelin CLI:
https://docs.openzeppelin.com/learn/connecting-to-public-test-networks

The Microsoft documentation on connecting to a PoA network is here:
https://docs.microsoft.com/en-us/azure/blockchain/templates/ethereum-poa-deployment#deploy-smart-contract-using-truffle

Combining the two you should end up with network.js like the following, where you would need to set the networkId and rpc_endpoint for the poa network.

networks.js

const { mnemonic } = require('./secrets.json');
const rpc_endpoint = "<Ethereum RPC endpoint>";
const HDWalletProvider = require('@truffle/hdwallet-provider');

module.exports = {
  networks: {
    development: {
      protocol: 'http',
      host: 'localhost',
      port: 8545,
      gas: 5000000,
      gasPrice: 5e9,
      networkId: '*',
    },
    poa: {
      provider: () => new HDWalletProvider(mnemonic, rpc_endpoint),
      networkId: 10101010,
      gasPrice: 0
    }
  },
};

You can check connectivity using npx oz accounts.
I would also try deploying a simple contract such as Box.sol from the documentation: https://docs.openzeppelin.com/learn/developing-smart-contracts#setting-up-a-solidity-project

Thank you for replying and teaching me about oz accounts

I note that you poa account has exactly the same code as my azure account except for the networkId which I"m sure is correct because, if I don’t use mine, it gives an error telling me to use it.

Even so, first returns to a command prompt.

The second one (called bad) actually worked enough to give me something but gave me an account that I didn’t recognize.

$ oz accounts
? Pick a network azure
$
$ oz accounts
? Pick a network bad
Accounts for dev-103098097:
Default: 0x00B72539621405B21ec5d5D931079792e2a5dE79
All:
- 0: 0x00B72539621405B21ec5d5D931079792e2a5dE79
$

My assumption is that if I can get connectivity (i.e. oz accounts), I should be able to deploy . . . .

Any further ideas?

TIA. – Mark

1 Like

So . . . . I just found your issue report

npx oz deploy hangs when deploying regular contract to Rinkeby #1469

Is it likely that this is my problem?
They don’t have BlockScout set up yet . . . . I guess I’ll have to push them unless there is a workaround.

Actually, as I write this, I’m guessing that this isn’t the problem because if it were, when I retried the deployment, it still believed that it needed the prerequisites added (unless that is a multi-step process that didn’t complete because of the above issue . . . . )

This is REALLY frustrating . . . .

It has nothing to do with any of my code (except my networks.js) since it hangs on the prerequisites.
oz accounts would seem to indicate that my networks.js is good.

Where do I go from here?

1 Like

It’s definitely an Azure PoA problem.

mwaser@DESKTOP-AUSCT6L:~/tutorial$ oz push --network ropsten
Nothing to compile, all contracts are up to date.
✓ Contract Counter deployed
✓ Contract Wallet deployed
All implementations have been deployed
1 Like

What’s really odd is the account information from oz accounts.
If I set up my networks.js to have a From: field, it doesn’t alter the returned account number at all
and that returned account number is nowhere in my MetaMask and I can’t import it without a private key

bad: {
      host: "etht5zt7j-dns-reg1.eastus2.cloudapp.azure.com", 
      port: 8540,
      network_id: 103098097,
      // optional config values:
      gas: 200000,
      gasPrice: 0,
      from: "0xc13b4e4cB7c2AF0D90A293d4d94De61Bf5317504"
}
$ oz accounts
? Pick a network bad
Accounts for dev-103098097:
Default: 0x00B72539621405B21ec5d5D931079792e2a5dE79
All:
- 0: 0x00B72539621405B21ec5d5D931079792e2a5dE79
$
1 Like

OK . . . . so this works perfectly on the Sokol PoA network

CODE:

poa: {
      provider: function() {
            return new HDWalletProvider(
              metamask_mnemonic,
           "https://sokol.poa.network")
      },
      network_id: 77,
      gas: 5000000,
      gasPrice: 1000000000
    },

END CODE/BEGIN ACCOUNTS & DEPLOY

$ oz accounts
? Pick a network poa
Accounts for dev-77:
Default: 0xc13b4e4cB7c2AF0D90A293d4d94De61Bf5317504
All:
- 0: 0xc13b4e4cB7c2AF0D90A293d4d94De61Bf5317504
$
$ oz push --network poa
Nothing to compile, all contracts are up to date.
? One or more linked dependencies are not yet deployed on dev-77.
Do you want to deploy them now? Yes
✓ Deploying openzeppelin-eth dependency to network dev-77
✓ Deploying @openzeppelin/contracts-ethereum-package dependency to network dev-77
✓ Contract Counter deployed
✓ Contract Wallet deployed
All implementations have been deployed
$
1 Like

Now, virtually the same code:

azure: {
      provider: function() {
        return new HDWalletProvider(
          metamask_mnemonic,
       "https://etht5zt7j-dns-reg1.eastus2.cloudapp.azure.com")
      },
      network_id: 103098097,
      gas: 200000,
      gasPrice : 0
 },

and it returns nothing when calling accounts.

$ oz accounts
? Pick a network azure
$

Note: I’ve tried it both with and without the port in the URL. It works with both – the one without the port is dog slow, presumably scanning ports, while the one with the port is fast. But both have the same effect (returning without any results)

1 Like

Now VERY slightly different format with the same values:

azure2: {
      host: "etht5zt7j-dns-reg1.eastus2.cloudapp.azure.com", 
      port: 8540,
      network_id: 103098097,
      gas: 200000,
      gasPrice: 0,
}

It returns like poa did EXCEPT that the account ID IS NOT CORRECT.

$ oz accounts
? Pick a network azure2
Accounts for dev-103098097:
Default: 0x00B72539621405B21ec5d5D931079792e2a5dE79
All:
- 0: 0x00B72539621405B21ec5d5D931079792e2a5dE79
$

And, of course, deploying hangs

$ oz push --network azure2
Nothing to compile, all contracts are up to date.
? One or more linked dependencies are not yet deployed on dev-103098097.
Do you want to deploy them now? Yes
⠹ Deploying openzeppelin-eth dependency to network dev-103098097
⠹ Deploying @openzeppelin/contracts-ethereum-package dependency to network dev-103098097
1 Like

I did try to add a from argument

azure2: {
      host: "etht5zt7j-dns-reg1.eastus2.cloudapp.azure.com", 
      port: 8540,
      network_id: 103098097,
      // optional config values:
      gas: 200000,
      gasPrice: 0,
      from: "0xc13b4e4cB7c2AF0D90A293d4d94De61Bf5317504"
}

But it still returned the exact same incorrect account.

Anyone have any guesses as to where that account came from or why using the HDWalletProvider works for sokol but not for Azure?

1 Like

Hi @MWaser,

I appreciate your frustration, though once you are connected it should get easier.

I hope you don’t mind, I deployed a contract to your Proof of Authority network.
Once you have it working, you may want to spin up a new network and shut this one down, as you have shared the RPC in a public forum.

For the RPC endpoint, we need to specify the port and http (rather than https)
I gleemed this information from the Microsoft documentation:

network.js

const { projectId, mnemonic } = require('./secrets.json');
const HDWalletProvider = require('@truffle/hdwallet-provider');
const rpc_endpoint = "http://etht5zt7j-dns-reg1.eastus2.cloudapp.azure.com:8540";

module.exports = {
  networks: {
    development: {
      protocol: 'http',
      host: 'localhost',
      port: 8545,
      gas: 5000000,
      gasPrice: 5e9,
      networkId: '*',
    },
    rinkeby: {
      provider: () => new HDWalletProvider(
        mnemonic, `https://rinkeby.infura.io/v3/${projectId}`
      ),
      networkId: 4,
      gasPrice: 10e9
    },
    poa: {
      provider: () => new HDWalletProvider(mnemonic, rpc_endpoint),
      networkId: 103098097,
      gasPrice: 0
    }
  },
};

Box.sol

I used the Box contract from the OpenZeppelin Learn guides

// contracts/Box.sol
pragma solidity ^0.5.0;

contract Box {
    uint256 private value;

    // Emitted when the stored value changes
    event ValueChanged(uint256 newValue);

    // Stores a new value in the contract
    function store(uint256 newValue) public {
        value = newValue;
        emit ValueChanged(newValue);
    }

    // Reads the last stored value
    function retrieve() public view returns (uint256) {
        return value;
    }
}

I ran into another issue, I suspect that this PoA network may not support the latest EVM version.

$ npx oz call
? Pick a network poa
? Pick an instance Box at 0x288A9140dfA42BCd6328B70ba6A3600D9A1C1943
? Select which function retrieve()
✖ Calling: 'retrieve' with no arguments
Error while trying to call 0x288A9140dfA42BCd6328B70ba6A3600D9A1C1943#retrieve(). Error: VM execution error.
$ npx oz send-tx
? Pick a network poa
? Pick an instance Box at 0x288A9140dfA42BCd6328B70ba6A3600D9A1C1943
? Select which function store(newValue: uint256)
? newValue: uint256: 42
✖ Calling: 'store' with:
- newValue (uint256): "42"
Error while trying to send transaction to 0x288A9140dfA42BCd6328B70ba6A3600D9A1C1943. Error: Error: The execution failed due to an exception.

To work around this, I compiled with an earlier version of the compiler.

Compile

$ npx oz compile --solc-version 0.5.0
✓ Compiled contracts with solc 0.5.0 (commit.1d4f565a)

Deploy

I used OpenZeppelin 2.8 RC2, otherwise if you are using an earlier version, you can use oz create

$ npx oz deploy
Nothing to compile, all contracts are up to date.
? Choose the kind of deployment regular
? Pick a network poa
? Pick a contract to deploy Box
✓ Deployed instance of Box
0x068851224B4851506094EA525186B703E0d1fa6b

Interact

$ npx oz send-tx
? Pick a network poa
? Pick an instance Box at 0x068851224B4851506094EA525186B703E0d1fa6b
? Select which function store(newValue: uint256)
? newValue: uint256: 42
✓ Transaction successful. Transaction hash: 0x56573a27181e5a48c34c984a0023282d231586e0843843f5b15d08b4ecb660d7
Events emitted:
 - ValueChanged(42)
$ npx oz call
? Pick a network poa
? Pick an instance Box at 0x068851224B4851506094EA525186B703E0d1fa6b
? Select which function retrieve()
✓ Method 'retrieve()' returned: 42
42

Let me know how you get on.

WOW!! Changing the https to http got my oz accounts to work correctly and my deployment is only failing due to the block gas limit (after I increased the transaction gas).

I don’t mind your testing by deploying a contract to my network at all. That’s actually why I posted the RPC. I’m sure that I’m going to bounce this sucker several times before we even think about going to production. :wink:

I guess my next step is increasing the block gas limit. You wouldn’t happen to know how to do it, would you? My preliminary googling is coming up short – but I’m going to stick with it until I win :wink:

Thank you SOOOOOOO much for your time and appreciation. I can’t believe that one little s can kill me so thoroughly (actually, I can believe it but . . . . geez . . . . ).

1 Like

Hi @MWaser,

About 18 months ago I spun up a few PoA networks on Azure. The configuration can be painful (though Microsoft documentation looks pretty good now), but once you get over that it should be ok. I have spent days on things like http vs https. So I have lots of empathy for what you are doing.

Appears like block gas limit is part of the settings when you configure the network, I don’t know if you can easily change after. So for now you may want to spin up another network:

Feel free to ask all the questions that you need.

As an aside, are you able to share what you are working on? Curious to learn what you are building on a POA network.

So . . . my next challenge is that

Additionally, there is a separate, unconfigurable data size limit for deploying new contracts. If your transaction involves deploying a new contract, it will be restricted to 48 KB.

Thanks

Microsoft Azure Blockchain Team
Wednesday, January 2, 2019 9:25 PM

Is there an easy way to break up and deploy the prerequisite upgradeable contract packages?

[Project description in next reply]

1 Like

The Government Blockchain Association (http://gbaglobal.org) is developing an open source cross-blockchain Government Business Blockchain Platform. The PoA Ethereum will be the core hub and central interface for cross-blockchain operations.

Eventually, I’d like to turn it into a crowd-sourced cognitive services platform (I’m also writing a book on that for Packt Publishing).

1 Like

Hi @MWaser,

It would be great if you wanted to share details on the project, I haven’t come across the GBA before. (If you wanted you could start a new topic in #general or I could move this discussion to there).

A post was split to a new topic: Can’t deploy contracts to my Azure PoA Ethereum because the dependencies are too large