In order to deploy a smart contract to the network we need three the following information:
From the web3js spec:
// deploy new contract
var contractInstance = MyContract.new([constructorParam1] [, constructorParam2], {data: '0x12345...', from: myAccount, gas: 1000000});
Correct me if I am wrong:
constructorParams - all the data that is passed to the smart contract constructor,
from - determines the address this contract is deployed from
gas - gas limit on how much this transaction can consume
What is data, is it sort of a compiled solidity code of the contract, if so why then do we need it if we have already specified ABI of this contract?
How do I get this data parameter? I also get an error in my console when I try to deploy the contract to the network without specifying data parameter:
Error: "invalid argument 0: json: cannot unmarshal hex string without 0x prefix into Go struct field SendTxArgs.data of type hexutil.Bytes"
Yes, data is the compiled byte code for your smart contract.
The ABI doesn't have the code for running the contract; it just describes the interface (what functions exist with what parameters).
You get the bytecode from the compiler. Without knowing what tool you're using, it's hard to be more specific.
const data = contract.methods.contractFunction(contractArgument).encodeABI()
This will encode a function of the contract into byte code, which can then be passed into the data parameter.
contractFunction(contractArgument)
will be different for you and the function you are wanting to call.
Related
I deployed a contract of a token that has up to nine other files imported to the finance blockchain. I have done everything I can read and try in order to verify it. But it keeps giving me error.
Compiler debug log:
Error! Unable to generate Contract ByteCode and ABI
Found the following ContractName(s) in source code : Address, Context, IERC20, IUniswapV2Factory, IUniswapV2Pair, IUniswapV2Router01, IUniswapV2Router02, Ownable, RentCoin, SafeMath
But we were unable to locate a matching bytecode (err_code_2)
For troubleshooting, you can try compiling your source code with the Remix - Solidity IDE and check for exceptions
My contract was compiled and deployed using Remix and optimization was set to 200. My compiler version is 0.6.12 and the link to the flattened contract is below:
https://drive.google.com/file/d/100J73q4hutqqmT1tZEuMn46YYFmzYaT0/view?usp=sharing
I understand that this contract involves constructors but I really need a practical guide on how to locate them and convert them to the right-abi-encoded JSON format that the verification page may accept.
I'm learning solidity on remix
I'm also referencing this open source api for token creation.
Right here they provide a _totalSupply() function that I'd like to wire to my smart contract so it shows the total amount of tokens why I deploy it.
What am doing wrong here?
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);
// add totalSupply here
_totalSupply(uint256 5000000000000000000000000000000000000000);
}
}
OpenZeppelin ERC20 _totalSupply is a private property, which means you can't access it from a derived contract (in your case Foobar).
GitHub link to the property definition
Solidity docs on visibility modifiers
Also your syntax is incorrect. If the property were at least internal, you could set its value as
_totalSupply = 5000000000000000000000000000000000000000;
or in a more readable way
_totalSupply = 5 * 1e39;
If you want to change its visibility, you'll need to copy the (parent) ERC20 contract to your IDE and change the import statement to reflect the new (local) location. Then you'll be able to update the property visibility in your local copy of the contract.
Mind that the OpenZeppelin ERC20 contains relative import paths (e.g. import "./IERC20.sol";). You'll need to rewrite these in your local copy as well, so that they point back to the GitHub locations. Otherwise, the compiler would be trying to import non-existing local files.
OpenZeppelin contracts automatically update totalSupply when you mint or burn tokens. They also automatically expose this as a variable you can read. You do not need, and you should not and you cannot set totalSupply by hand, because then the number of distributed tokens would not match the total supply.
As the title says I cannot verify my smart contract on Etherscan. I read all the solutions from similar threads with no luck. I'm getting the following error :
Error! Unable to generate Contract ByteCode and ABI
Found the following ContractName(s) in source code : AtariToken, ERC20Interface, SafeMath
But we were unable to locate a matching bytecode (err_code_2)
Compiler Version: v0.6.8+commit.0bbfe453
Optimization Enabled: True
Runs: 200
ByteCode (what we are looking for):
60806040526401cf8d20e060025534801561001957600080fd5b506040516120403803806120408339818101604052602081101561003c57600080fd5b8101908080519060200190929190505050806002819055506002546000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555050611f97806100a96000396000f3fe608060405234801561001057600080fd5b50600436106100f55760003560e01c80635d1b1e6d11610097578063d395100211610066578063d39510021461070c578063d5e1bdb3146107e9578063dd62ed3e1461094f578063ff294f45146109c7576100f5565b80635d1b1e6d1461045757806370a08231146105cb57806395d89b4114610623578063a9059cbb146106a6576100f5565b806318160ddd116100d357806318160ddd146102c057806323b872dd146102de578063313ce5671461036457806335ee5f8714610388576100f5565b806306fdde03146100fa578063095ea7b31461017d57806312cb70c7146101e3575b600080fd5b610102610aa4565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610142578082015181840152602081019050610127565b50505050905090810190601f16801561016f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101c96004803603604081101561019357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610add565b604051808215151515815260200191505060405180910390f35b6102a6600480360360408110156101f957600080fd5b810190808035906020019064010000000081111561021657600080fd5b82018360208201111561022857600080fd5b8035906020019184600183028401116401000000008311171561024a57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929080359060200190929190505050610bcf565b604051808215151515815260200191505060405180910390f35b6102c8610e3f565b6040518082815260200191505060405180910390f35b61034a600480360360608110156102f457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610e49565b604051808215151515815260200191505060405180910390f35b61036c6111c4565b604051808260ff1660ff16815260200191505060405180910390f35b6104416004803603602081101561039e57600080fd5b81019080803590602001906401000000008111156103bb57600080fd5b8201836020820111156103cd57600080fd5b803590602001918460018302840111640100000000831117156103ef57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506111c9565b6040518082815260200191505060405180910390f35b6105b16004803603606081101561046d57600080fd5b810190808035906020019064010000000081111561048a57600080fd5b82018360208201111561049c57600080fd5b803590602001918460018302840111640100000000831117156104be57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561052157600080fd5b82018360208201111561053357600080fd5b8035906020019184600183028401116401000000008311171561055557600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019092919050505061129f565b604051808215151515815260200191505060405180910390f35b61060d600480360360208110156105e157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611737565b6040518082815260200191505060405180910390f35b61062b61177f565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561066b578082015181840152602081019050610650565b50505050905090810190601f1680156106985780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6106f2600480360360408110156106bc57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506117b8565b604051808215151515815260200191505060405180910390f35b6107cf6004803603604081101561072257600080fd5b810190808035906020019064010000000081111561073f57600080fd5b82018360208201111561075157600080fd5b8035906020019184600183028401116401000000008311171561077357600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019092919050505061199a565b604051808215151515815260200191505060405180910390f35b610939600480360360408110156107ff57600080fd5b810190808035906020019064010000000081111561081c57600080fd5b82018360208201111561082e57600080fd5b8035906020019184600183028401116401000000008311171561085057600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290803590602001906401000000008111156108b357600080fd5b8201836020820111156108c557600080fd5b803590602001918460018302840111640100000000831117156108e757600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050611b83565b6040518082815260200191505060405180910390f35b6109b16004803603604081101561096557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611d27565b6040518082815260200191505060405180910390f35b610a8a600480360360408110156109dd57600080fd5b81019080803590602001906401000000008111156109fa57600080fd5b820183602082011115610a0c57600080fd5b80359060200191846001830284011164010000000083111715610a2e57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929080359060200190929190505050611dae565b604051808215151515815260200191505060405180910390f35b6040518060400160405280600a81526020017f4174617269546f6b656e0000000000000000000000000000000000000000000081525081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000806003846040518082805190602001908083835b60208310610c085780518252602082019150602081019050602083039250610be5565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690506000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054831115610ca957600080fd5b610cfa836000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611f2e90919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610d8d836000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611f4590919063ffffffff16565b6000808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3600191505092915050565b6000600254905090565b60008060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115610e9657600080fd5b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115610f1f57600080fd5b610f70826000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611f2e90919063ffffffff16565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061104182600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611f2e90919063ffffffff16565b600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611112826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611f4590919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600081565b6000806003836040518082805190602001908083835b6020831061120257805182526020820191506020810190506020830392506111df565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690506000808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054915050919050565b6000806003856040518082805190602001908083835b602083106112d857805182526020820191506020810190506020830392506112b5565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905060006003856040518082805190602001908083835b602083106113665780518252602082019150602081019050602083039250611343565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690506000808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205484111561140757600080fd5b600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205484111561149057600080fd5b6114e1846000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611f2e90919063ffffffff16565b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506115b284600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611f2e90919063ffffffff16565b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611683846000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611f4590919063ffffffff16565b6000808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a36001925050509392505050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6040518060400160405280600481526020017f415441520000000000000000000000000000000000000000000000000000000081525081565b60008060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482111561180557600080fd5b611856826000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611f2e90919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506118e9826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054611f4590919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b60008073ffffffffffffffffffffffffffffffffffffffff166003846040518082805190602001908083835b602083106119e957805182526020820191506020810190506020830392506119c6565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415611b4157336003846040518082805190602001908083835b60208310611a905780518252602082019150602081019050602083039250611a6d565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055507fb783ac61be9a63ecee43ec4875521540beaa0d5935b0d80543c42bd4aae8a0c9826040518082815260200191505060405180910390a160019050611b7d565b7f2dcc15de21ffd99c8ff84e0d8289119ca55fff2e9b4a1e2270baa5840cb82487826040518082815260200191505060405180910390a1600090505b92915050565b6000806003846040518082805190602001908083835b60208310611bbc5780518252602082019150602081019050602083039250611b99565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905060006003846040518082805190602001908083835b60208310611c4a5780518252602082019150602081019050602083039250611c27565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549250505092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b6000806003846040518082805190602001908083835b60208310611de75780518252602082019150602081019050602083039250611dc4565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905082600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925856040518082815260200191505060405180910390a3600191505092915050565b600082821115611f3a57fe5b818303905092915050565b600080828401905083811015611f5757fe5b809150509291505056fe{ipfs}64736f6c634300060800330000000000000000000000000000000000000000000000000000000000000000
- vs what we got -
We tried looking for a match from the list of compiled contract bytecode outputs (as listed below), but was unable to find an exact match.
1) AtariToken
60806040526401cf8d20e060025534801561001957600080fd5b506040516112823803806112828339818101604052602081101561003c57600080fd5b5051600281905533600090815260208190526040902055611220806100626000396000f3fe608060405234801561001057600080fd5b50600436106100f55760003560e01c80635d1b1e6d11610097578063d395100211610066578063d3951002146104f4578063d5e1bdb31461059a578063dd62ed3e146106c3578063ff294f45146106f1576100f5565b80635d1b1e6d1461036f57806370a082311461049a57806395d89b41146104c0578063a9059cbb146104c8576100f5565b806318160ddd116100d357806318160ddd1461025d57806323b872dd14610277578063313ce567146102ad57806335ee5f87146102cb576100f5565b806306fdde03146100fa578063095ea7b31461017757806312cb70c7146101b7575b600080fd5b610102610797565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561013c578181015183820152602001610124565b50505050905090810190601f1680156101695780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101a36004803603604081101561018d57600080fd5b506001600160a01b0381351690602001356107bd565b604080519115158252519081900360200190f35b6101a3600480360360408110156101cd57600080fd5b810190602081018135600160201b8111156101e757600080fd5b8201836020820111156101f957600080fd5b803590602001918460018302840111600160201b8311171561021a57600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295505091359250610824915050565b61026561094d565b60408051918252519081900360200190f35b6101a36004803603606081101561028d57600080fd5b506001600160a01b03813581169160208101359091169060400135610953565b6102b5610a9c565b6040805160ff9092168252519081900360200190f35b610265600480360360208110156102e157600080fd5b810190602081018135600160201b8111156102fb57600080fd5b82018360208201111561030d57600080fd5b803590602001918460018302840111600160201b8311171561032e57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610aa1945050505050565b6101a36004803603606081101561038557600080fd5b810190602081018135600160201b81111561039f57600080fd5b8201836020820111156103b157600080fd5b803590602001918460018302840111600160201b831117156103d257600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295949360208101935035915050600160201b81111561042457600080fd5b82018360208201111561043657600080fd5b803590602001918460018302840111600160201b8311171561045757600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295505091359250610b24915050565b610265600480360360208110156104b057600080fd5b50356001600160a01b0316610d47565b610102610d62565b6101a3600480360360408110156104de57600080fd5b506001600160a01b038135169060200135610d82565b6101a36004803603604081101561050a57600080fd5b810190602081018135600160201b81111561052457600080fd5b82018360208201111561053657600080fd5b803590602001918460018302840111600160201b8311171561055757600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295505091359250610e3a915050565b610265600480360360408110156105b057600080fd5b810190602081018135600160201b8111156105ca57600080fd5b8201836020820111156105dc57600080fd5b803590602001918460018302840111600160201b831117156105fd57600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295949360208101935035915050600160201b81111561064f57600080fd5b82018360208201111561066157600080fd5b803590602001918460018302840111600160201b8311171561068257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610fae945050505050565b610265600480360360408110156106d957600080fd5b506001600160a01b03813581169160200135166110ae565b6101a36004803603604081101561070757600080fd5b810190602081018135600160201b81111561072157600080fd5b82018360208201111561073357600080fd5b803590602001918460018302840111600160201b8311171561075457600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092955050913592506110d9915050565b6040518060400160405280600a81526020016920ba30b934aa37b5b2b760b11b81525081565b3360008181526001602090815260408083206001600160a01b038716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a35060015b92915050565b6000806003846040518082805190602001908083835b602083106108595780518252601f19909201916020918201910161083a565b51815160209384036101000a6000190180199092169116179052920194855250604080519485900382019094205433600090815291829052939020546001600160a01b03909316935050508311156108b057600080fd5b336000908152602081905260409020546108d0908463ffffffff6111a216565b33600090815260208190526040808220929092556001600160a01b03831681522054610902908463ffffffff6111b416565b6001600160a01b038216600081815260208181526040918290209390935580518681529051919233926000805160206111cb8339815191529281900390910190a35060019392505050565b60025490565b6001600160a01b03831660009081526020819052604081205482111561097857600080fd5b6001600160a01b03841660009081526001602090815260408083203384529091529020548211156109a857600080fd5b6001600160a01b0384166000908152602081905260409020546109d1908363ffffffff6111a216565b6001600160a01b038516600090815260208181526040808320939093556001815282822033835290522054610a0c908363ffffffff6111a216565b6001600160a01b0380861660009081526001602090815260408083203384528252808320949094559186168152908190522054610a4f908363ffffffff6111b416565b6001600160a01b038085166000818152602081815260409182902094909455805186815290519193928816926000805160206111cb83398151915292918290030190a35060019392505050565b600081565b6000806003836040518082805190602001908083835b60208310610ad65780518252601f199092019160209182019101610ab7565b51815160209384036101000a600019018019909216911617905292019485525060408051948590038201909420546001600160a01b0316600090815290819052929092205495945050505050565b6000806003856040518082805190602001908083835b60208310610b595780518252601f199092019160209182019101610b3a565b51815160209384036101000a600019018019909216911617905292019485525060405193849003810184205488516001600160a01b03909116955060009460039450899350918291908401908083835b60208310610bc85780518252601f199092019160209182019101610ba9565b51815160209384036101000a600019018019909216911617905292019485525060408051948590038201909420546001600160a01b038781166000908152928390529490912054931693505050841115610c2157600080fd5b6001600160a01b0382166000908152600160209081526040808320338452909152902054841115610c5157600080fd5b6001600160a01b038216600090815260208190526040902054610c7a908563ffffffff6111a216565b6001600160a01b038316600090815260208181526040808320939093556001815282822033835290522054610cb5908563ffffffff6111a216565b6001600160a01b0380841660009081526001602090815260408083203384528252808320949094559184168152908190522054610cf8908563ffffffff6111b416565b6001600160a01b038083166000818152602081815260409182902094909455805188815290519193928616926000805160206111cb83398151915292918290030190a350600195945050505050565b6001600160a01b031660009081526020819052604090205490565b6040518060400160405280600481526020016320aa20a960e11b81525081565b33600090815260208190526040812054821115610d9e57600080fd5b33600090815260208190526040902054610dbe908363ffffffff6111a216565b33600090815260208190526040808220929092556001600160a01b03851681522054610df0908363ffffffff6111b416565b6001600160a01b038416600081815260208181526040918290209390935580518581529051919233926000805160206111cb8339815191529281900390910190a350600192915050565b6000806001600160a01b03166003846040518082805190602001908083835b60208310610e785780518252601f199092019160209182019101610e59565b51815160209384036101000a60001901801990921691161790529201948552506040519384900301909220546001600160a01b031692909214159150610f73905057336003846040518082805190602001908083835b60208310610eed5780518252601f199092019160209182019101610ece565b51815160209384036101000a600019018019909216911617905292019485525060408051948590038201852080546001600160a01b0319166001600160a01b03979097169690961790955586845293517fb783ac61be9a63ecee43ec4875521540beaa0d5935b0d80543c42bd4aae8a0c9949381900390930192915050a150600161081e565b6040805183815290517f2dcc15de21ffd99c8ff84e0d8289119ca55fff2e9b4a1e2270baa5840cb824879181900360200190a150600061081e565b6000806003846040518082805190602001908083835b60208310610fe35780518252601f199092019160209182019101610fc4565b51815160209384036101000a600019018019909216911617905292019485525060405193849003810184205487516001600160a01b03909116955060009460039450889350918291908401908083835b602083106110525780518252601f199092019160209182019101611033565b51815160209384036101000a600019018019909216911617905292019485525060408051948590038201909420546001600160a01b03968716600090815260018352858120979091168152959052505090912054949350505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6000806003846040518082805190602001908083835b6020831061110e5780518252601f1990920191602091820191016110ef565b51815160209384036101000a600019018019909216911617905292019485525060408051948590038201852054336000818152600185528381206001600160a01b039093168082529285528390208a9055898752915190965086959194507f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92593509081900390910190a35060019392505050565b6000828211156111ae57fe5b50900390565b6000828201838110156111c357fe5b939250505056feddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef{ipfs}64736f6c634300060800330000000000000000000000000000000000000000000000000000000000000000
2) SafeMath
60566023600b82828239805160001a607314601657fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfe{ipfs}64736f6c634300060800330000000000000000000000000000000000000000000000000000000000000000
Here's a link to my smart contract:
https://ropsten.etherscan.io/address/0x1a0699201b5549328c5eb5332fc07dbc888df60b#code
Some solutions suggested a problem with the ABI in case you use constructor arguments. On my last contract I had constructor arguments, and tried the solution without any results. But for this contract I didn't specify any value for my constructor argument, so my ABI has a value of0000000000000000000000000000000000000000000000000000000000000000, and hardcoded the totalSupply value in my code, however I'm still getting the same error.
I have been attempting to deploy a contract using the Truffle framework, I have recently been testing these contracts on the development network.
My contract was very large and when I attempted to deploy it to a test net, I was instructed to split it up so that the contract wouldn't exceed the gas limit. Although, bearing in mind this contract did deploy onto the development network with the default gas limit.
So I took out parts of the contract and derived another contract from the base and added the deleted sections in there. I attempted to deploy it to the development network in order to test it again, I now get the error:
'Error: The contract code couldn't be stored, please check your gas amount.'
So the steps I took was to:
Change my gasLimit to 100,000,000 which didn't solve it
Check to see if my contract is 'abstract'
My understanding of this is that a contract is abstract if it or its
parent has any functions without an implementation. Mine don't.
I then deleted all of the code other than the constructor from the
derived contract and I still get this error
I deleted the file and the deployment worked with just my base contract as before, therefore the parent contract must not have any non-implemented functions AND it still doesn't work when I attempt to derive an empty contract from it (making sure nothing was abstract in the derived contract).
I then split my migration files up so that the migrations happen
separately, still no luck.
My parent contract is around 300 lines long so no point posting it all in here - I know some people will say 'it may just be too large' however, it deployed when it was 500 lines long on the dev network and now it is only 250 lines long with a deriving contract of 275 lines long, it does not deploy.
The error:
Running migration: 2_deploy_contracts.js
Replacing ERC20Token...
... 0xcae613274de1aa278e7ae5d1239f43445132a417d98765a4f227ea2439c9e4fc
ERC20Token: 0xeec918d74c746167564401103096d45bbd494b74
Replacing Crowdsale...
... 0x0ffc7291d84289c1391a81ed9f76d1e165285e3a3eadc065732aa288ea049b3a
Crowdsale: 0x0d8cc4b8d15d4c3ef1d70af0071376fb26b5669b
Saving successful migration to network...
... 0x7f351d76f61f7b801913f59b808688a2567b64933cdfdcf78bb18b0bf4e4ff69
Saving artifacts...
Running migration: 3_more_deployed_contracts.js
Deploying StagedSale...
... 0x216136bb24d317b140a247f10ec4d6791559739111a85932133cd4a66b12a1d9
Error encountered, bailing. Network state unknown. Review successful
transactions manually.
Error: The contract code couldn't be stored, please check your gas
amount.
at Object.callback
(/usr/local/lib/node_modules/truffle/build/cli.bundled.js:329221:46)
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:39618:25
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:331159:9
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:175492:11
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:314196:9
at XMLHttpRequest.request.onreadystatechange
(/usr/local/lib/node_modules/truffle/build/cli.bundled.js:329855:7)
My base contract is too large to post, and it deploys fine on its own meaning its not abstract.
My derived contract is:
pragma solidity ^0.4.16;
import "./SafeMath.sol";
import "./Crowdsale.sol";
contract StagedSale is Crowdsale {
using SafeMath for uint256;
/*
* Setup the contract and transfer ownership to appropriate beneficiary
*/
function StagedSale
(
uint256 _stage1Duration,
uint256 _stage2Duration
) public {
uint256 stage1duration = _stage1Duration.mul(1 minutes);
uint256 stage2duration = _stage2Duration.mul(1 minutes);
}
My migration file for the derived contract:
var StagedSale = artifacts.require("./StagedSale.sol");
module.exports = function(deployer) {
const stage1Duration = 1;
const stage2Duration = 1;
deployer.deploy(StagedSale, stage1Duration, stage2Duration);
};
I have posted this question here as I fear this may be a common issue with Truffle deployment.
To conclude, I don't believe this has anything to do with the actual gas limits and is instead, failing for some unknown reason and printing this error message anyway.
I've found a fix to this, basically if you are inheriting from a base contract, you must deploy the base contract within the inherited contracts constructor like so:
OLD VERSION:
Simply deployed the base, then deployed the inheriting contract with a reference to 'is Crowdsale' in class name
deployer.deploy(ERC20Token, initialAmount, tokenName, decimalUnits,tokenSymbol).then(function() {
return deployer.deploy(Crowdsale, softCap, hardCap, etherCostOfEachToken, sendFundsTo, toChecksumAddress(ERC20Token.address), durationInMinutes);
});
deployer.deploy(FinalizableSale);
NEW VERSION
Only deploy the inheriting contract and create a new instance of base within that constructor
deployer.deploy(ERC20Token, initialAmount, tokenName, decimalUnits,tokenSymbol).then(function() {
return deployer.deploy(Finalizable, softCap, hardCap, etherCostOfEachToken, sendFundsTo, toChecksumAddress(ERC20Token.address), durationInMinutes);
});
FINALIZABLE CONSTRUCTOR:
function FinalizableSale(uint256 _fundingGoalInEthers, uint256 _fundingLimitInEthers, uint256 _etherCostOfEachToken, address _sendFundsTo, address _tokenAddress, uint256 _durationInMinutes)
Crowdsale(_fundingGoalInEthers, _fundingLimitInEthers, _etherCostOfEachToken, _sendFundsTo, _tokenAddress, _durationInMinutes)
{
//do something
}
NOTE: That the base contract is initialised BEFORE the opening brackets to the constructor function.
I no longer get the 'out of gas' error and my contract runs as before.
Trying to follow the wiki example for go ethereum to create a basic contract:
https://github.com/ethereum/go-ethereum/wiki/Contracts-and-Transactions
Everything seems to work until I get down until the last line:
source = "contract test { function multiply(uint a) returns(uint d) { return a * 7; } }"
contract = eth.compile.solidity(source).test
primaryAddress = eth.accounts[0]
# **Problems start here **
MyContract = eth.contract(abi);
contact = MyContract.new(arg1, arg2, ...,{from: primaryAddress, data: evmCode})
What is the "abi" argument for the eth.contract method? Also, what would I put in the "evmCode" argument? In this particular example, seems like I would put in an integer for "arg1" but not sure what the full example should look like.
The ABI is the interface that your contract exposes. "evmCode" is the Ethereum byte code for your contract.
To work around your problem, go to https://chriseth.github.io/browser-solidity/ and plug your Solidity in. The Bytecode field on the right will give you the value for "evmCode" and Interface will give you the ABI.
You can also copy the snippet from "Web3 deploy" and paste it in your code to deploy your contract.
ABI is basically which is the public facing interface that shows what methods are available to call.
The simplest way to get the abi would be to use https://remix.ethereum.org . just paste in your code and in Contract tab At the bottom of the column you’ll find a link that says Contract details which is basically the ABI json
Conversely you could also use the contracts.Introduction.interface api of web3 to get the abi.
ABI is representation of smart contract that can be read using java script .To read the data from a deployed contract account in etherum , you'll need some extra details like abi.
Steps to get abi of any smart contract:
1.Each contract has contract hash address like this:0x0D8775F648430679A709E98d2b0Cb6250d2887EF
2.Go to etherscan.io and search your contract address hash in search bar and you will get contract.
3.In contract go to code and there you can find this abi
can check this link to find abi
You could try using tools like Etherlime shape or Truffle boxes to have a whole sample project with contract, tests, and usage into the js. From here you could start moving forward.
ABI is Application Binary Interface. A contract when compiled by solidity compiler returns an object with different methods. ABI and Bytecode are basically used methods. ABI is used to interact with your contracts and frontend (if using node) and bytecode is used for deploying to Rinkeby (or any Ethereum network).
For example:
Contract is:
pragma solidity ^0.4.17;
contract Inbox
{
string public message;
function Inbox(string initialMessage) public{
message = initialMessage;
}
function setMessage(string newMessage) public{
message = newMessage;
}
}
Its ABI is:
interface:
[{
"constant":false,"inputs":[{
"name":"newMessage","type":"string"
}]
,"name":"setMessage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"
}
,{
"constant":true,"inputs":[],"name":"message","outputs":[{
"name":"","type":"string"
}]
,"payable":false,"stateMutability":"view","type":"function"
}
,{
"inputs":[{
"name":"initialMessage","type":"string"
}]
,"payable":false,"stateMutability":"nonpayable","type":"constructor"
}]
This is returned after compiling the contract. You can see it consists of methods used in our contract.