Brownie Contract Deploy: 401 Client Error

Hello,
I’m trying to figure out how to deploy a smart contract onto the Polygon Mumbai Test network using Moralis. Here’s how I’m attempting to deploy using Python/Brownie. Unfortunately, I’m getting the following error on deploy:

 File "brownie/_cli/run.py", line 50, in main
    return_value, frame = run(
  File "brownie/project/scripts.py", line 103, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File "./scripts/integration_test/deploy_factory_only_Moralis.py", line 63, in main
    deploy_factory_contract()
  File "./scripts/integration_test/deploy_factory_only_Moralis.py", line 52, in deploy_factory_contract
    nft_factory = deploy_factory(networkType=network_type,
  File "./scripts/deploy_factory.py", line 15, in deploy_factory
    factory_contract = MyFactory.deploy(
  File "brownie/network/contract.py", line 528, in __call__
    return tx["from"].deploy(
  File "brownie/network/account.py", line 510, in deploy
    receipt, exc = self._make_transaction(
  File "brownie/network/account.py", line 744, in _make_transaction
    response = self._transact(tx, allow_revert)  # type: ignore
  File "brownie/network/account.py", line 842, in _transact
    return web3.eth.send_transaction(tx)
  File "web3/eth.py", line 719, in send_transaction
    return self._send_transaction(transaction)
  File "web3/module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str,
  File "web3/manager.py", line 197, in request_blocking
    response = self._make_request(method, params)
  File "web3/manager.py", line 150, in _make_request
    return request_func(method, params)
  File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
  File "web3/middleware/formatting.py", line 76, in apply_formatters
    response = make_request(method, params)
  File "web3/middleware/gas_price_strategy.py", line 89, in middleware
    return make_request(method, (transaction,))
  File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
  File "web3/middleware/formatting.py", line 74, in apply_formatters
    response = make_request(method, formatted_params)
  File "web3/middleware/attrdict.py", line 33, in middleware
    response = make_request(method, params)
  File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
  File "web3/middleware/formatting.py", line 74, in apply_formatters
    response = make_request(method, formatted_params)
  File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
  File "web3/middleware/formatting.py", line 74, in apply_formatters
    response = make_request(method, formatted_params)
  File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
  File "web3/middleware/formatting.py", line 74, in apply_formatters
    response = make_request(method, formatted_params)
  File "web3/middleware/buffered_gas_estimate.py", line 40, in middleware
    return make_request(method, params)
  File "brownie/network/middlewares/catch_tx_revert.py", line 24, in process_request
    result = make_request(method, params)
  File "brownie/network/middlewares/geth_poa.py", line 21, in process_request
    return middleware_fn(method, params)
  File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
  File "web3/middleware/formatting.py", line 76, in apply_formatters
    response = make_request(method, params)
  File "web3/middleware/exception_retry_request.py", line 114, in middleware
    return make_request(method, params)
  File "web3/providers/rpc.py", line 88, in make_request
    raw_response = make_post_request(
  File "web3/_utils/request.py", line 49, in make_post_request
    response.raise_for_status()
  File "requests/models.py", line 953, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
HTTPError: 401 Client Error: Unauthorized for url: https://speedy-nodes-nyc.moralis.io/<moralis_account>/polygon/mumbai

Here’s what I’m doing to deploy. Any ideas what I’m doing wrong?
Regards,
TJ

from scripts.factory.Utils import get_network
from brownie import accounts, My_Factory
from scripts.factory.F_Account import AccountType
from scripts.deploy_factory import deploy_factory

'''From: 
- https://admin.moralis.io/speedyNodes
- https://www.youtube.com/watch?v=CLcGRlcxsbc

assert_added> brownie networks add Polygon moralis_mumbai host='https://speedy-nodes-nyc.moralis.io/<moralis_account>/polygon/mumbai' name='Mumbai (moralis)' chainid=80001 explorer='https://mumbai.polygonscan.com/'
    stdout> Brownie v1.17.2 - Python development framework for Ethereum

    SUCCESS: A new network 'Mumbai (moralis)' has been added
      └─Mumbai (moralis)
        ├─id: moralis_mumbai
        ├─chainid: 80001
        ├─explorer: https://mumbai.polygonscan.com/
        └─host: https://speedy-nodes-nyc.moralis.io/<moralis_account>/polygon/mumbai
        
assert_added> brownie accounts new test_acct_1
assert_added> brownie accounts new test_acct_2
    (venv) bash:~/PycharmProjects/Brownie_Minis/NFT_Factory$ brownie accounts new test_acct_1
    Brownie v1.17.2 - Python development framework for Ethereum

    Enter the private key you wish to add: <metamask_exported_private_key>
    Enter the password to encrypt this account with:
    SUCCESS: A new account 'gen_acct_1' has been generated with the id 'test_acct_1'
    
    (venv) bash:~/PycharmProjects/Brownie_Minis/NFT_Factory$ brownie accounts new test_acct_2
    Brownie v1.17.2 - Python development framework for Ethereum

    Enter the private key you wish to add: <metamask_exported_private_key>
    Enter the password to encrypt this account with:
    SUCCESS: A new account 'gen_acct_2' has been generated with the id 'test_acct_2' '''

#
# pycharm.bash> brownie run scripts/deploy_factory_only_Moralis.py --network moralis_mumbai


def deploy_factory_contract():
    # --------- DEPLOY FACTORY CONTRACT  ---------
    network_type = get_network()
    nft_symbol = 'SFI'
    AccountType.DAO.set_address(address='gen_acct_1')       # test account
    AccountType.LICENSOR.set_address(address='gen_acct_2')       # test account

    nft_factory = deploy_factory(networkType=network_type,
                                 dao_acct=AccountType.DAO,
                                 licensor_acct=AccountType.LICENSOR,
                                 nft_symbol=nft_symbol,
                                 gas_price=875000000
                                 )
    print('Factory Deployed!')
    # --------- DEPLOY FACTORY CONTRACT  ---------


def main():
    deploy_factory_contract()

Also, I tried using the Brownie console as described in the video. My stuff looks like this:

Brownie Console

bash> brownie console --network moralis_mumbai
brownie> act_1 = accounts.load('test_acct_1')
brownie> act_2 = accounts.load('test_acct_2')
brownie> My_Factory.deploy(act_1, act_2, 'SFI', {'from': act_1, 'gas_price': 875000}, publish_source=True)

Result

  • The console has been churning for ~30min at this point. Current output:
Transaction sent: 0xc4f31c0bd9bd97e3a9a380a94bf536b9b35ffe9135760122eafdd56159dff940
  Gas price: 0.000875 gwei   Gas limit: 2640973   Nonce: 0
  Waiting for confirmation... /

Testing out in Remix and attempted to deploy to Rinkeby from there. Seems like there may be an issue in my smart contract that resulted in a revert. I will provide more details after I’ve dug a bit deeper.

1 Like

Folks…I wanted to give a quick status. It looks like the problem was in my smart contracts. I was using 2 contracts: an NFT and an NFT factory. Something I was doing was allowing all my unit tests in Brownie to succeed, but resulted in an infinite gas state when trying to deploy to Rinkeby. I have since reduced to a single contract and can verify Rinkeby deployment.

Given that I’m still learning the blockchain ecosystem, I plan to do a giggle test in Remix prior to each deploy since that seemed to catch a error when Brownie did not.

1 Like