Giter Club home page Giter Club logo

Comments (11)

rubo avatar rubo commented on August 19, 2024 2

Same here. It's virtually not possible to deploy contracts with TronBox. Both to Shasta and Mainnet. The error occurs on the local devnet but rarely.
It fails randomly either on Migrations or on one of the subsequent contracts. Moreover, it actually deploys the contract, reports an error, and quits. Thus, the deployment process interrupts for no reason. The config in tronbox.js is correct, there are way more than enough funds on the deployer's account.
I tried to deploy exactly with the same settings and the same issuer address with TronWeb, and it works. It also works with the full node HTTP API but not with TronBox. Clearly, there's a problem with TronBox (v2.7.25) and it's extremely annoying.

from tronbox.

cathy-lishipu avatar cathy-lishipu commented on August 19, 2024

The problem should be that some proposals are not approved after the private net was deployed.
you can refer to the end of this article: https://developers.tron.network/docs/tron-private-chain

from tronbox.

kevholder avatar kevholder commented on August 19, 2024

Where should I set this?

{
    "key": 0,
    "value": 300000 // 5 minutes in ms
}

And is there a script to setup all the proposals? I am not sure how to do it.

from tronbox.

kevholder avatar kevholder commented on August 19, 2024

I was able to get the first contract to work using this configuration file: https://github.com/TRON-US/docker-tron-quickstart/blob/master/conf/full.conf

But now, the second contract won't deploy...

$ npx tronbox migrate --reset --network development
Using network 'development'.

Running migration: 1_initial_migration.js
  Deploying Migrations...
  Migrations:
    (base58) TJ4ouv6hM7qDr46QqidRyEh3zTQWfpZnXU
    (hex) 4158d03a8504acd98e1f1a69cc552e67b92156cefc
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Deploying Exchange...
ERROR: Contract Exchange has not been deployed on the network.
For more details, check the transaction at:
http://127.0.0.1:18190/wallet/gettransactionbyid?value=65ceb635c52c5122c49d822bbe390a59ea232a5a202986b289f7af7268d2467b
If the transaction above is empty, most likely, your address had no bandwidth/energy to deploy the contract.

The transaction says this:

 "contractRet": "OUT_OF_ENERGY"

But it is weird because the deployment address has a LOT of TRX.

from tronbox.

cathy-lishipu avatar cathy-lishipu commented on August 19, 2024

I think it because the proposal didn't take effect. The default is six hours.

from tronbox.

kevholder avatar kevholder commented on August 19, 2024

How do I lower the default ?

from tronbox.

kevholder avatar kevholder commented on August 19, 2024

I am trying to run this script to set the proposals, but I am getting an error:

#!/bin/bash
proposals=$(<proposals.json)
witness_address="TPL66VK2gCXNCD7EJg9pgJRfqcRazjhUZY"
data="{\"owner_address\":\"${witness_address}\",\"visible\": true,\"parameters\":${proposals}}"
echo $data | jq
curl -X POST "${TRON_API_URL}/wallet/proposalcreate" -d \
  "${data}"
$ ./create-proposals.sh
{
  "owner_address": "TPL66VK2gCXNCD7EJg9pgJRfqcRazjhUZY",
  "visible": true,
  "parameters": [
    {
      "key": 9,
      "value": 1
    },
    {
      "key": 10,
      "value": 1
    },
    {
      "key": 11,
      "value": 20
    },
    {
      "key": 17,
      "value": 250000000000
    },
    {
      "key": 11,
      "value": 10
    },
    {
      "key": 19,
      "value": 100000000000
    },
    {
      "key": 15,
      "value": 1
    },
    {
      "key": 18,
      "value": 1
    },
    {
      "key": 16,
      "value": 1
    },
    {
      "key": 20,
      "value": 1
    },
    {
      "key": 26,
      "value": 1
    },
    {
      "key": 30,
      "value": 1
    },
    {
      "key": 5,
      "value": 16000000
    },
    {
      "key": 31,
      "value": 160000000
    },
    {
      "key": 32,
      "value": 1
    }
  ]
}
{"Error":"class org.tron.core.exception.ContractValidateException : Bad chain parameter id"}

from tronbox.

kevholder avatar kevholder commented on August 19, 2024

Here is address resource before first contract deployment:

{
  "freeNetLimit": 5000,
  "TotalNetLimit": 43200000000,
  "TotalEnergyLimit": 50000000000
}

And after:

{
  "freeNetUsed": 979,
  "freeNetLimit": 5000,
  "TotalNetLimit": 43200000000,
  "TotalEnergyLimit": 50000000000
}

But the address has a lot of TRX (1000000000 TRX), why is there an OUT_OF_ENERGY error?

from tronbox.

kevholder avatar kevholder commented on August 19, 2024

Here's the contract I try to deploy. I was able to deploy it fine on mainnet.. but I'm getting that OUT_OF_ENERGY error on privatenet.

pragma solidity >= 0.5.0 < 0.7.0;
pragma experimental ABIEncoderV2;

import "./IERC20.sol";

contract Exchange {
  address owner;

  enum SwapType {
    Buy,
    Sell
  }

  struct SwapEntry {
    address maker;

    bool fulfilled;
    bool canceled;

    SwapType swapType;
    IERC20 erc20Token;

    uint inputAmount;
    uint outputAmount;
    address restrictToAddress;
  }

  event SwapEntryCreated(uint swapEntryId);
  event SwapEntryFulfilled(uint swapEntryId);
  event SwapEntryCanceled(uint swapEntryId);


  SwapEntry[] public swapEntries;

  constructor() public {
    owner = msg.sender;
  }

  function swapEntriesLength() external view returns (uint) {
    return swapEntries.length;
  }

  function swapEntriesArray() external view returns (SwapEntry[] memory) {
    return swapEntries;
  }

  function isFulFillable(uint swapEntryId) public view returns (bool) {
    SwapEntry storage swapEntry = swapEntries[swapEntryId];
    return !swapEntry.fulfilled && !swapEntry.canceled;
  }

  function isAuthorizedToFulfill(address addr, uint swapEntryId) internal view returns (bool) {
    SwapEntry storage swapEntry = swapEntries[swapEntryId];
    // not restricted
    if (swapEntry.restrictToAddress == address(0)) {
      return true;
    }
    return addr == swapEntry.restrictToAddress;
  }

  function _createSwapEntry(SwapType swapType, IERC20 erc20Token, uint inputAmount, uint outputAmount, address restrictToAddress) internal returns (uint) {
    address maker = msg.sender;
    SwapEntry memory swapEntry = SwapEntry({
      maker: maker,
      fulfilled: false,
      canceled: false,
      swapType: swapType,
      erc20Token: erc20Token,
      inputAmount: inputAmount,
      outputAmount: outputAmount,
      restrictToAddress: restrictToAddress
    });
    // push and return index of entry
    swapEntries.push(swapEntry);
    uint swapEntryId = swapEntries.length - 1;
    emit SwapEntryCreated(swapEntryId);
    return swapEntryId;
  }

  function createBuySwapEntry(IERC20 erc20Token, uint outputAmount,
                              address restrictToAddress) external payable returns (uint) {
    uint inputAmount = msg.value;
    return _createSwapEntry(SwapType.Buy, erc20Token, inputAmount, outputAmount, restrictToAddress);
  }

  function createSellSwapEntry(IERC20 erc20Token, uint inputAmount, uint outputAmount, address restrictToAddress) external returns (uint) {
    address sender = msg.sender;
    address recipient = address(this);
    // transfer the tokens to smart contract to ensure the swap is guaranteed to succeed if fulfilled
    erc20Token.transferFrom(sender, recipient, inputAmount);
    return _createSwapEntry(SwapType.Sell, erc20Token, inputAmount, outputAmount, restrictToAddress);
  }

  function cancelSwapEntry(uint swapEntryId) external returns (uint) {
    require(isFulFillable(swapEntryId), "only fulfillable swap entry can be canceled");
    SwapEntry storage swapEntry = swapEntries[swapEntryId];
    address payable maker = address(uint160(swapEntry.maker));
    require(msg.sender == maker || msg.sender == owner, "only owner creator of swap entry can cancel it");
    swapEntry.canceled = true;
    if (swapEntry.swapType == SwapType.Buy) {
      maker.transfer(swapEntry.inputAmount);
    } else if (swapEntry.swapType == SwapType.Sell) {
      swapEntry.erc20Token.transfer(maker, swapEntry.inputAmount);
    } else {
      assert(false);
    }
    emit SwapEntryCanceled(swapEntryId);
  }

  function fulfillBuySwap(uint swapEntryId) external returns (uint) {
    require(isFulFillable(swapEntryId), "swap entry is not fulfillable");
    require(isAuthorizedToFulfill(msg.sender, swapEntryId), "swap entry is restricted to another address");
    SwapEntry storage swapEntry = swapEntries[swapEntryId];
    require(swapEntry.swapType == SwapType.Buy, "swap entry is not of type Buy");
    swapEntry.fulfilled = true;

    address maker = swapEntry.maker;
    address payable taker = address(uint160(msg.sender));

    swapEntry.erc20Token.transferFrom(taker, maker, swapEntry.outputAmount);

    taker.transfer(swapEntry.inputAmount);
    emit SwapEntryFulfilled(swapEntryId);
  }

  function fulfillSellSwap(uint swapEntryId) external payable returns (uint) {
    require(isFulFillable(swapEntryId), "swap entry is not fulfillable");
    require(isAuthorizedToFulfill(msg.sender, swapEntryId), "swap entry is restricted to another address");
    SwapEntry storage swapEntry = swapEntries[swapEntryId];
    require(swapEntry.swapType == SwapType.Sell, "swap entry is not of type Sell");
    require(msg.value == swapEntry.outputAmount, "value is not exactly equal to swapEntry outputAmount");
    swapEntry.fulfilled = true;

    address payable maker = address(uint160(swapEntry.maker));
    address taker = msg.sender;

    swapEntry.erc20Token.transfer(taker, swapEntry.inputAmount);

    maker.transfer(swapEntry.outputAmount);
    emit SwapEntryFulfilled(swapEntryId);
  }
}

from tronbox.

kevholder avatar kevholder commented on August 19, 2024

I tried deploying a smaller contract and it worked so I assume the issue is that the privatenet is configured to not accept larger contract?

from tronbox.

zyumingfit avatar zyumingfit commented on August 19, 2024

If the account balance is sufficient, the out-of-energy error still occurs, it is because the feelimit in the transaction is too small

from tronbox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.