Brownie Eth - Changing networks does not change the network.chain.id - brownie

I am trying to programatically deploy a Smart Contract via Brownie to multiple test networks.
The following code works, however when I switch networks the network.chain.id renames the same as the first one. I need this chain_id so I can store the contract addresses that have been deployed for each network.
for name in ["fuji-testnet", "polygon-test", "goerli"]:
network.disconnect()
network.connect(network_name, launch_rpc=False)
print(network.show_active(), network.is_connected(), network.chain.id)
The above code will output:
fuji-testnet True 43113
polygon-test True 43113
goerli True 43113
Which is not what I need.

You will find that this is a bug in brownie at the time of writing but you can access the true chain_id with
brownie.web3.chain_id

Related

I'm testing a multi-sig contract using RIDE but I have got the following error?

I'm trying to test out creating a multi-sig test but I keep on running into the same issue => Error occured Error: State check failed. Reason: negative waves balance: 3MwqXaytrPKxhCBaa4pc36SHjFYtqoMo2gX, old: 0, new: -1000000
I've imported the seed into client, and the waves address I get is 3P9rLYJniWsMKeUzq95bzYp7694ffwWbWEG which has 0.2 Waves.
Why is the account address provided with ide.wavesplatform.com different from the address I get from importing the seed phrase into client?
Maybe you used the mainnet client but on ide.wavesplatform.com uses testnet, or the other way round that would be the most reasonable explanation.
It could also be that in one of both cases you have an extra space somewhere (mostly at the end) in the seed.
Yes the IDE by default is set to testnet,
you can set the network byte in IDE in settings (top right corner):
for testnet, Node URL: https://testnodes.wavesnodes.com and T=testnet.
for main net, Node URL: http://nodes.wavesnodes.com and W=mainnet.

gas required exceeds allowance or always failing transaction on Geth private blockchain but works fine in others

I have created a private blockchain using geth. I also have a contract in which there is a function which call another function it third contract to set an address. I can call this function on Local blockchains like testRPC and Ganache blockchain, Even it works in TestNet. But Once I setup the private blockchain using (geth). I get this error:
Gas estimation errored with the following message (see below).
The transaction execution will likely fail. Do you want to force sending?
gas required exceeds allowance or always failing transaction
I have enough ETH in the caller account and also
I have enough ETH in the caller account and also
GasLimit is high enough
The functions does not have any loop or fancy operation, setting an address and some condition checks
The node is an Ubuntu 16.04
geth -v --> 1.8.12-stable
// in contract 1
function func(address addr) public returns (bool result) {
Cantract2 c = Cantract2(addr);
if (!c.setAddress(..)) {
return false;
}
.....
return true;
}
You might want to check the genesis file/chain specification of your private test chain.
There is a variable called block gas limit that affects how much gas you can spend on each block. I recall that the default value used to be very low back in the days and maybe you are using such a config. What you could do:
check the block gas limit in the dev chain configuration and increase it as to your needs
or let the local test chain run for some time as the client will vote up the default block gas limit slowly, allowing you for larger transactions per block

NodeJs blockchain on private ethereum

I have created simple blockchain application using NodeJS. The blockchain data file is getting stored on local File System. There is no mining blocks, no difficulty level involved in this blockchain.
Please suggest, if I can host this application on private ethereum / hyperledge, and what all changes I would need to do for this? Below code I'm using for creating blocks.
Sample Genesis Block
[{"index":0,"previousHash":"0","timestamp":1465154705,"transaction":{"id":"0","transactionHash":"0","type":"","data":{"StudInfo":[{"id":"","studentId":"","parenterId":"","schemeId":"","batchId":"","instructorId":"","trainingId":"","skillId":""}]},"fromAddress":""},"hash":"816534932c2b7154836da6afc367695e6337db8a921823784c14378abed4f7d7"}]
Sample Code(NodeJS)
var generateNextBlock = (blockData) => {
var previousBlock = getLatestBlock();
var nextIndex = previousBlock.index + 1;
var nextTimestamp = new Date().getTime() / 1000;
var nextHash = calculateHash(nextIndex, previousBlock.hash, nextTimestamp, blockData);
return new Block(nextIndex, previousBlock.hash, nextTimestamp, blockData, nextHash);
};
var calculateHashForBlock = (block) => {
return calculateHash(block.index, block.previousHash, block.timestamp, block.transaction);
};
var calculateHash = (index, previousHash, timestamp, transaction) => {
return CryptoJS.SHA256(index + previousHash + timestamp + transaction).toString();
};
var addBlock = (newBlock) => {
if (isValidNewBlock(newBlock, getLatestBlock())) {
blockchain.push(newBlock);
blocksDb.write(blockchain);
}
};
var isValidNewBlock = (newBlock, previousBlock) => {
if (previousBlock.index + 1 !== newBlock.index) {
console.log('invalid index');
return false;
} else if (previousBlock.hash !== newBlock.previousHash) {
console.log('invalid previoushash');
return false;
} else if (calculateHashForBlock(newBlock) !== newBlock.hash) {
console.log(typeof (newBlock.hash) + ' ' + typeof calculateHashForBlock(newBlock));
console.log('invalid hash: ' + calculateHashForBlock(newBlock) + ' ' + newBlock.hash);
return false;
}
return true;
};
Congratulations if you have gotten this far you have successfully setup Geth on AWS. Now we will go over how to configure an Ethereum node. Make sure you are in your home directory on your cloud server with the pwd command and then create a new folder called whatever you want to create the genesis block of your Ethereum blockchain. You can do this with the following commands. The first command is to create the folder, change directory into the folder and then create a file called genesis.json.
mkdir mlg-ethchain cd mlg-ethchain nano genesis.json
To create a private blockchain you need to define the genesis block. Genesis blocks are usually embedded in the client but with Ethereum you are able to configure a genesis block using a json object. Paste the following JSON object into your genesis.json file and we explain each variable in the following section.
{
"nonce": "0xdeadbeefdeadbeef",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x0",
"gasLimit": "0x8000000",
"difficulty": "0x400",
"Mixhash":
"0x0000000000000000000000000000000000000000000000000000000000000000", "coinbase": "0x3333333333333333333333333333333333333333",
"alloc": {
}
}
The coinbase is the default address of the mining address. Because you have not created a wallet yet this can be set to whatever you want provided that it is a valid Ethereum address. Difficulty is how hard it is for a miner to create a new block. For testing and development purposes it is recommended that you start with a low difficulty and then increase it. The parentHash is the hash of the parent block which doesnt exist because this is the first block in the chain. The gasLimit is the maximum amount of gas that is required to execute a transaction or send tokens from one account to another. The nonce is a random number for this block. This is the number that every miner has to guess to define the block but for the first block it must be hardcoded. You are able to provide any extraData is the extraData section. In the alloc section you can allocate a number of premined tokens or ether to certain addresses at the beginning of the blockchain. We do not want to do this so we will keep it blank.
After you have confirmed this you can check the file to make sure it has been configured correctly with the cat command. From the same directory input this command.
cat genesis.json
From what I understand, your JS code does some sort of low-level block generation (albeit in a centralised/standalone way). I'm not sure of the purpose of that code, but it's not an app that you could "port to" Ethereum or Hyperledger [Fabric], since the role of those blockchain engines is precisely to implement the block generation logic for you.
A JS app designed to work with Ethereum wouldn't do any of the block management. At the contrary, it would perform high-level and client-level interaction with a smart contract, which is basically a class (similar to Java classes) available on the whole network and whose methods are guaranteed by the network to do what they're meant to. Your JS app would essentially call the smart contract's methods as a client without caring about any block production issues.
In other, more vague but maybe more familiar terms:
Client: the JS app
Server/backend: the smart contract
Infrastructure/engine: Ethereum
On Ethereum, the way you get to the smart contract as a client is by sending RPC calls in JSON (hence the name JSON-RPC) to the contract's methods. The communication is done by embedding that JSON over HTTP to an Ethereum node, preferably your own. In Javascript, a few libraries such as web3 give you a higher-level abstraction view so that you don't need to care about JSON-RPC and you can think of your contract's methods as normal Javascript functions.
Also, since you're asking about private Ethereum: another consequence of that distribution of layers is that client code and smart contracts don't need to care about whether the Ethereum network is a public or a private one, i.e. what consensus protocol is in place. To make a bold analogy, it's similar to how SQL queries or schemas stay the same no matter how the database is persisted on disk.
Interaction with Hyperledger Fabric is similar in concept, except that you do plain REST calls to an HTTP endpoint exposed by the network. I'm not sure what client-level abstraction libraries are available.

Error sending value to Ethereum smart contract

I have geth 1.5.2 and work on testnet with Mist-linux64-0-8-7. I stuck at a simple issue when I try to send some ether (value) to my contract by calling any function.
For example, even this dummy function does not work with non-zero value but works normally with zero value:
function t() returns (uint){
return 1;
}
What is surprising here that I can see a warning in Mist with the message "It seems this transaction will fail. If you submit it, it may consume all the gas you send."
This does not depend on the gas amount that I provide.
Even if I put 500,000 of gas the transaction seem not to complete.
You can see its result here:
https://testnet.etherscan.io/tx/0x3206118530079d1b416dc649c6f0a89283f9457e9189f259b3429cf0c6a998d0
There is a message
Warning! Error encountered during contract execution [Bad jump
destination]
I tried to run different functions in different contracts. I was even using sendTransaction functionality to do the same from geth console directly but I still can't make it work.
I didn't find if anybody had similar problem. Please help me if you have any idea.
From Solidity 0.4 onwards:
Functions that want to receive Ether have to specify the new payable
modifier (otherwise they throw).
A throw consumes all gas, so use function t() payable returns (uint).

Java code to get currently running beanstalk version label?

From within a running Java application running on beanstalk, how can I get the beanstalk version label that is currently running?
[Multiple Edits later...]
After a few back-and-forth comments with Sony (see below), I wrote the following code which works for me now. If you put meaningful comments in your version label when you deploy, then this will tell you what you're running. We have a continuous build environment, so we can get our build environment to supply a label that leads to the check-in comments for the related code. Put this all together, and your server can tell you exactly what code its running relative to your source code check-ins. Really useful for us. OK now I'm actually answering my own question here, but with invaluable help from Sony. Seems a shame you can't remove the hard-coded values and query for those at runtime.
String getMyVersionLabel() throws IOException {
Region region = Region.getRegion(Regions.fromName("us-west-2")); // Need to hard-code this
AWSCredentialsProvider credentialsProvider = new ClasspathPropertiesFileCredentialsProvider();
AWSElasticBeanstalkClient beanstalk = region.createClient(AWSElasticBeanstalkClient.class, credentialsProvider, null);
String environmentName = System.getProperty("PARAM2", "DefaultEnvironmentName"); // Need to hard-code this too
DescribeEnvironmentsResult environments = beanstalk.describeEnvironments();
for (EnvironmentDescription ed : environments.getEnvironments()) {
if (ed.getEnvironmentName().equals( environmentName)) {
return "Running version " + ed.getVersionLabel() + " created on " + ed.getDateCreated());
break;
}
}
return null;
}
You can use AWS Java SDK and call this directly.
See the details of describeApplicationVersions API for how to get all the versions in an application.Ensure to give your regions as well (otherwise you will get the versions from the default AWS region).
Now, if you need to know the version deployed currently, you need to call additionally the DescribeEnvironmentsRequest. This has the versionLabel, which tells you the the version currently deployed.
Here again, if you need to know the environment name in the code, you need to pass it as a param to the beanstalk configuration in the aws console, and access as a PARAM.