No Eth for accounts of private network of `truffle develop`? - ethereum

I'm developing a Solidity program. I started truffle develop
> truffle develop
Truffle Develop started at http://localhost:9545/
Accounts:
(0) 0x627306090abab3a6e1400e9345bc60c78a8bef57
(1) 0xf17f52151ebef6c7334fad080c5704d77216b732
(2) 0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef
(3) 0x821aea9a577a9b44299b9c15c88cf3087f3b5544
(4) 0x0d1d4e623d10f9fba5db95830f7d3839406c6af2
(5) 0x2932b7a2355d6fecc4b5c0b6bd44cc31df247a2e
(6) 0x2191ef87e392377ec08e7c08eb105ef5448eced5
(7) 0x0f4f2ac550a1b4e2280d04c21cea7ebd822934b5
(8) 0x6330a553fc93768f612722bb8c2ec78ac90b3bbc
(9) 0x5aeda56215b167893e80b4fe645ba6d5bab767de
Mnemonic: candy maple cake sugar pudding cream honey rich smooth crumble sweet treat
truffle(develop)> migrate
Using network 'develop'.
Running migration: 1_initial_migration.js
Replacing Migrations...
... 0x3bfa69d31cbe12e43f20204daaf24e764a084ade586c3b417099d2e2deccc8eb
Migrations: 0x8cdaf0cd259887258bc13a92c0a6da92698644c0
Saving successful migration to network...
... 0xd7bc86d31bee32fa3988f1c1eabce403a1b5d570340a3a9cdba53a472ee8c956
Saving artifacts...
Running migration: 2_deploy_contracts.js
Replacing TutorialToken...
... 0x56fb0c0933ee395055db66976427f050e24dadda018b113d8f0cc03dc7229043
TutorialToken: 0x345ca3e014aaf5dca488057592ee47305d9b3e10
Saving successful migration to network...
... 0xf36163615f41ef7ed8f4a8f192149a0bf633fe1a2398ce001bf44c43dc7bdda0
Saving artifacts...
truffle(develop)>
Then I setup MetaMask to connect the Private network of http://localhost:9545/. However, I cannot do any transaction because the MetaMask account has 0 ETH? How to add some test ETH for development?
Update
I realized that the account created by metamask has different addresses than the ten test accounts created by truffle develop. How to import the test account into Metamask?

When you setup Metamask you have to import the existing account (I can't remember the exact wording of the option, but you'll figure it out) and then provide the mnemonic Truffle gave you: candy maple cake sugar pudding cream honey rich smooth crumble sweet treat.

Instead of importing the Truffle test accounts into Metamask, you can start Truffle with a predefined set of test accounts using the --account option. Just specify your private key and the amount of Wei you want to start with.
testrpc --account
"YOUR_PRIVATE_KEY,300000000000000000000"
This will initialize your account with 300 ether. Note that you have to pass in your key, not the address.
You can specify multiple accounts with separate --account options.

Instead of importing testrpc/ganache-cli accounts to metamask, you can start testrpc/ganache-cli giving the metamask's mnemonic seed.
Here's how to do it :
Open metamask
click on the burger menu on the top-right corner of the pop-in
Metamask main pop-in
Choose reveal seed word at the bottom of the settings pop-in
Metamask option bottom pop-in
Enter your password. Seed words should been revealed then. Copy/paste them somewhere safe.
When launching testrpc, here's what you can use :
Here's what i use :
testrpc -m "<seed words>"
if you use ganache-cli, which is the new version of testrpc, that's the same :
ganache-cli -m "<seed words>"
This is what i personally use :
ganache-cli -b 15 --debug -m "<seed words>"
-b 15 means i want 15 second block time. I put this to have some delay as on the main net. When deploying your contracts and making requests you won't have instant answer. If you want you can put decrement this number if you want some delay but not wait too much.
--debug will allow you to have some more information like the assembly instructions made when making a call. It can be useful to know what fails or where the contract instructions stops.

After you run Truffle develop and the console prints out the 10 accounts along with the private keys, copy one of the accounts private keys then go to Metamask > Import Account > Select Type = Private Key then past the copied private key in and then you should see the account with ETH in it.
Note: All 10 accounts should have 100 Eth except the first that used a small amount of Eth to bootstrap the chain.

Related

DeployedBytecode doesn't match

so I encountered a weird issue with deploying bytecodes via a deployer contract. On 1 of 5 deployed contracts via the same compilation round & deployment flow I ended having a different deployedBytecode (but same bytecode) as with my original truffle compiled source. Therefore I can't get it verified. The issue seems that the address of the deployer contract is part of the deployedBytecode (while on my local file it is the null address). The issue is also only for 1 contract, while all 5 contracts share the same code (especially around the deployer address mentioned inside the contract.
So here i.e. is the deployer contract (+ verified source code):
https://polygonscan.com/address/0xd54716865c58d11e7c39c3cf634d9e919c0c6cce#code
I deployed my contract (SignerVaultV1.sol) via that tx:
https://polygonscan.com/tx/0x4d6e3a002b448e675ba6a2374737d4eaf0e18b163a57a66c09109ba332c8c5e3
The bytecode of it is exactly the same as on my local file, but if the deployedBytecodes are compared, 3 changes can be seen: Diff between online vs offline deployedBytecode (I can't post pics yet^^)
The difference in it is the address of the deployer contract (d54716865c58d11e7c39c3cf634d9e919c0c6cce). But like I said, the deployerContract delivered multiple contracts, all are correct, only this one is having that issue and I cant figure it out why.
I personally would like to get that contract verified without having to redeploy it (and maybe rund into the same issue...) I tried already to alter the source code to match the online deployedBytecode, but it seems also a harsh idea :D
Well after testing different ways, I dont honestly why, but sending a verification request via hardhat got it working... I couldn't manually verify or via truffle, but hardhat seems to know the magic for the last contract :)

No job show up in Runs page while trying to run a Chainlink node locally

I am trying to fulfil requests on my local test chainlink node on rinkeby (following https://docs.chain.link/docs/fulfilling-requests/) but can't see any job runs appear on my operator ui.
The Oracle contract is at 0xA66f738a4688A9E51c2c6FF901CC3B11ce31AE6C
The ATestnetConsumer contract is at 0x977129EE2f404F4327A2A60C5fD9E57890D85FD0
My job toml screenshot below
Have confirmed my .env that it is running the rinkeby wss url from infura and the chain is 4 and the link token contract address is 0x01BE23585060835E02B77ef475b0Cc51aA1e0709
My node wallet has ETH and LINK. Both the contracts have Link too (but no ETH).
I run the setFulfillmentPermission function in remix with my Node wallet address and true
When I execute the requestEthereumPrice function with my oracle address and job id, I can see the LINK being sent by the ATestnetConsumer contract to the Oracle contract but no job run gets created in my local Chainlink node.
Confirming that the job hasn't run, I get the 0 value when I run the currentPrice function on ATestnetConsumer.
Can anyone please point me to where I am going wrong? Thanks in advance!
Finally got it to work. Posting my two findings as I do think the documentation needs an update to account for these.
The external job id in the Jobs screen on the Operator UI has dashes in them. To use them in the ATestnetConsumer contract you need to remove the dashes (so 0e84f38985eb4edb98c2e2a09b589666 and not 0e84f389-85eb-4edb-98c2-e2a09b589666).
The direct request toml doesn't seem to work as is. I had to append allowunrestrictednetworkaccess="true" to the fetch section so it becomes
fetch [type="http" method=GET url="$(decode_cbor.get)" allowunrestrictednetworkaccess="true"]

Requesting airdrop of 1 SOL on the devnet

I have properly setup a Solana wallet on the devnet, using these commands:
curl https://release.solana.com/v1.8.6/solana-install-init-x86_64-pc-windows-msvc.exe --output C:\solana-install-tmp\solana-install-init.exe --create-dirs
C:\solana-install-tmp\solana-install-init.exe v1.8.6
solana-keygen new --outfile C:/Users/Usermame/.config/solana/devnet.json
solana config set --keypair C:/Users/Usermame/.config/solana/devnet.json
solana config get
And it successfully created a Solana wallet. However, when I ran:
solana airdrop 1
It said:
Requesting airdrop of 1 SOL
Error: unable to confirm transaction. This can happen in situations such as transaction expiration and insufficient fee-payer funds
I have successfully airdropped 1 SOL to a Solana wallet on a devnet before, I don't know why this is not working.
Can anyone help me with this please?
Thank you!
Sometimes the devnet runs out of the faucets due to some dev asking for more than required faucets.
Have ran into same problem many times now.
One such instance was highlighted by core-contributor on the community group.
SOLUTION:
Either you can wait for validators to mint new faucets
OR
Ask for faucet in discord. That should do.
As mentioned before, sometimes the devnet is out; however, that is also just a potential message you get when the devnet(or any net) is down as well. You can ask in the server; otherwise, you can try other networks like the test network or deploying locally in the meantime.

Solidity - Add Token Logo

Glad to see blockchain development support on Stack Overflow as resources as very scarce nowadays.
I'm a new kid trying to learn this ecosystem.
How can I add an image logo to a token that I've already created and deployed on remix.ethereum.org?
Should I have done this before deploying it?
Newbie question: Once deployed the same code can never modified?
I'm currently interacting with the token on BSC - seems that all BSC tokens are created as a fork of Solidity and the ETH ERC20 paradigm. (?)
This is my code
pragma solidity ^0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
contract Foobar is ERC20 {
constructor(uint256 initialSupply) public ERC20("Foobar", "FOO") {
_mint(msg.sender, initialSupply);
}
}
Short answer: No, once you deploy a contract to the mainnet, you can't modify nor delete it, it'll be in the blockchain forever (unless you're using a testnet or a private blockchain network to test the contract).
Long answer:
Once a contract is deployed, it can never be modified nor deleted, the only thing you can modify is it's storage (variables that the contract uses) by calling it's defined functions, but you can't modify the logic behind it. If you messed up, you'll need to fix your contract, and re-deploy.
Take in mind that heavy tests and thoughtful inspections are advised before you deploy a contract to the mainnet and set an app into production (and even more if you'r contract will handle sensitive values), mainly because even if you screw up and re-deploy, if you had said contract work in production, its extremly difficult to fix.
For example: You make you'r own tiny bank, the contract recives eth, and it stores it a variable a mapping of addresses with a variable that keeps a count of how much eth from the total eth that the contract is holding is for each user.
contract Bank {
// mapping of address with current money value.
mapping (address user => uint money) balance;
constructor(){}
function withdraw(uint memory money) public {
// Require money parameter is not empty.
require(money != 0, "Can't withdraw 0 eth");
// Big issue here, if we send the money, and then update the balance,
// the user will be able to withdraw money even if hi's balance turns
// to 0 if he spams the withdraw function before he runs out of money.
// The good way would be the other way around, first update balance, and then send.
// Check if the user has enough money.
if (balance[msg.sender].money >= money) {
// Send money
address(msg.sender).transfer(money);
// Update balance.
balance[msg.sender].money -= money;
}
}
...
}
Now this has a critical issue, if someone withdraws money twice very fast, it skips a check iteration that checks if the user has enough money in it's balance to withdraw.
Now to fix this, you'll need to quickly withdraw all the money that the contract has and it's mapping(address user => uint money) ... mapping data, fix and re-deploy the contract, manually send all the money to the new contract, and also set the previous data that it had, and if that wasn't enough you'll need to change you'r front-end app to connect with the new contract.
I know its a long example, but when you start coding contracts from 0, you have to understand that testing and revising the contract is a must.
Once a contract is deployed, it cannot be modified nor deleted, it's there forever, alteast in the mainned, that's why you use private blockchains such as Ganache, or use a public testnet (Ropsten, Kovan, Rinkeby, Goerli).
Also about the logo, most tokens don't have their "logo" in their contract ( unless you're making a NFT [ ERC721 ] ), yet, if you still want to add a logo that anyone can access from your contract, i'd suggest to make a state variable that holds its value (string mainly).
The value can be a IPFS hash (IPFS is a decentralized file system that allows you to upload files of any kind, it will return a hash once it's uploaded, and you can access you'r file via https://HASHTOKEN.ipfs.infura-ipfs.io/, for example:
https://bafybeibctnxu7zpatp3caj2gevofs2oirdvdyo6yulxk2hfyaewxib3pj4.ipfs.infura-ipfs.io/
soo in you'r case, you can upload the logo there, grab the hash, and store it in you'r contract, then in your frontend app you'll only need to add the hash to the url.
A second way of adding you'r logo would be to turn you'r image into base64 and paste the whole thing into you'r contract, that way you have literally the image in the contract, yet, i don't recommend this last solution since base64 strings can get very large depending on how heavy is the file, and the heavier you'r contract is, the more gas it will use when you deploy it, and more expensive for the users when they try to use it.
Yet, if what you mean is to add a logo on sites such as BscScan, you can find a guide here.

Go-Ethereum custom network: how to limit contract creations?

I have created custom blockchain using go-ethereum
My network has 2 miners nodes with unlocked accounts and then a public node with a locked account that only broadcast transactions to the miners
I run the public node like this:
geth --datadir standard1/ --syncmode 'full' --port 30392 --rpc --rpcport 9578 --rpccorsdomain '*' --rpcaddr 'MY PUBLIC ADDRESS HERE' --ws --wsaddr "MY PUBLIC ADDRESS HERE" --wsorigins "*" --wsport 9579 --wsapi 'db,eth,net,web3,txpool,miner' --networkid 22 --gasprice '1'
The thing is that if someone sends a contract creation to the public node (using MyEtherWallet for example) the contract submition will be broadcasted and mined.
I found this: https://ethereum.stackexchange.com/questions/11091/is-there-any-way-to-disable-contract-creation-on-a-private-network
But..
a. how can a miner filter the transactions? do i need to create my own fork of go-ethereum with specific logic for this?
b. Is there any way to limit the contract creations? or a way to allow only one contract deployed?
c. I can query the transactions using web3js and check for contract creations, but is there a way to delete the contracts if i own the mining/sealers nodes?
d. Maybe i can ban an address that is submitting a contract? is that possible?
I think in Ethereum it is not possible to control who can send transactions as it is an open network and public blockchain. If you are looking to implement this think you have to switch to a private blockchain, I'd recommend hyperledger.
Even if you fork geth anyone who has access to the genesis file and everything can connect to the network and then mine the contract creation transactions on his nodes.
If you are willing to put in some development work, you can fork geth to remove the CREATE and CREATE2 opcodes. By doing so you could remove the ability to create new opcodes.
If you control the majority of hash power on your chain, you could prevent all others from mining transactions with these Opcodes. If someone connects to your chain and mines an invalid transaction, your nodes would drop this block as invalid and continue to mine your blocks.