I started with v0.6 and connected my node to an operator (called Oracle at the time)
pragma solidity ^0.6.0;
import "#chainlink/contracts/src/v0.6/Oracle.sol";
contract MyOperator is Oracle {
constructor(address _link) Oracle(_link) public {}
}
My client contract using those libs
pragma solidity ^0.6.6;
import "#chainlink/contracts/src/v0.6/ChainlinkClient.sol";
import "#openzeppelin/contracts/access/Ownable.sol";
I had to connect them using setFulfiullmentPermissions at the time:
await operator.setFulfillmentPermission(nodeAddress, true, {
from: owner,
});
=======
I then moved to v0.7 with my Operator being
pragma solidity ^0.7.0;
import "#chainlink/contracts/src/v0.7/dev/Operator.sol";
contract MyOperator is Operator {
constructor(address _link, address owner) Operator(_link, owner) public {}
}
My client contract using those libs
pragma solidity ^0.7.0;
import "#chainlink/contracts/src/v0.7/ChainlinkClient.sol";
import "#openzeppelin/contracts/access/Ownable.sol";
this time the authorization code looked like this
let tx = await operator.setAuthorizedSenders([nodeAddress], { from: owner });
=====
Now trying to migrate to chainlink v0.8
I see an OperatorInterface but not a real contract here in develop: https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/interfaces/OperatorInterface.sol
Why isn't the Operator implementation part of the v0.8 ?
If I am including a contract Operator v0.7 in my project, truffle is all confused with versions mismatch.
I couldn't find a resource online about someone deploying a node with v0.8.
How should I go about migrating to v0.8, what should I deploy as an Operator for my node, please?
The Operator is only implemented in ^0.7. version currently.
You can use Hardhat instead of Truffle, which supports multiple solc versions in a project, and then deploy the Operator using ^0.7 and deploy clients which interact with it in v0.8.
Related
I am using Remix to compile and deploy my smart contract to Rinkeby and RSK test networks.
I don't understand why the bytecode of my contract on Rinkeby explorer is different from the metadata.data.deployedBytecode.object in Remix artifacts and also different from evm.deployedBytecode.object coming from solcjs compiler. I also tried this on RSK and I got the same issue.
That's what I do in Remix:
I create a MegaHonk.sol file in contracts folder
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.7;
contract MegaHonk {
uint256 public count;
event LoudSound(address indexed source);
function honk() external {
require(tx.origin != msg.sender, 'EOA not allowed');
count += 1;
emit LoudSound(tx.origin);
}
}
I select the appropriate compiler version 0.8.7, select Environment: Injected provider - Metamask, compile and deploy to Rinkeby. The contract successfully deploys. Then I go to Rinkeby explorer, find my contract bytecode and compare it with the one in remix-file-explorer/contracts/artifacts/MegaHonk.js in the metadata.data.deployedBytecode.object property.
Bytecode from Rinkeby is 1348 symbols long and
Bytecode from Remix is 1350 symbols long.
The exact same thing happens when I am compiling the same smart contract with solcjs compiler. I use the right version 0.8.7 and these input parameters:
const input = {
language: 'Solidity',
settings: {
outputSelection: {
'*': {
'*': ['evm.deployedBytecode', 'evm.bytecode'],
},
},
optimizer: {
enabled: false,
},
},
sources: {
'MegaHonk.sol': {
content: MegaHonk,
},
},
};
Why does this happen? What compiler parameters should I use to make the bytecodes identical in the Remix artifacts, solcjs compiler and in blockchain explorer (Ethereum or RSK testnets)?
I am using the following contract from Ethernaut and did sudo npm i #openzeppelin/contracts
pragma solidity 0.6.0;
import "#openzeppelin/contracts/math/SafeMath.sol";
contract CoinFlip {
using SafeMath for uint256;
uint256 public consecutiveWins;
uint256 lastHash;
uint256 FACTOR = 57896044618658097711785492504343953926634992332820282019728792003956564819968;
constructor() public {
consecutiveWins = 0;
}
function flip(bool _guess) public returns (bool) {
uint256 blockValue = uint256(blockhash(block.number.sub(1)));
if (lastHash == blockValue) {
revert();
}
lastHash = blockValue;
uint256 coinFlip = blockValue.div(FACTOR);
bool side = coinFlip == 1 ? true : false;
if (side == _guess) {
consecutiveWins++;
return true;
} else {
consecutiveWins = 0;
return false;
}
}
}
However, I'm still getting this error regarding SafeMath contract not being found even after installing all the openzeppelin contracts: Error: Could not find #openzeppelin/contracts/math/SafeMath.sol from any sources
My configurations below:
Truffle v5.1.39 (core: 5.1.39)
Solidity - 0.6.0 (solc-js)
Node v16.13.1
Web3.js v1.2.1
The problem is your version selection.
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/solc-0.6/contracts/utils/SafeCast.sol";
This one is for solidity 0.6.0 the version you are currently using.
but you are using
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeMath.sol
which is for solidity >= 0.8.0
When you install openzeppelin contracts with npm as you did, you install the version with the current tag. The current tag is right now at Solidity version ^0.8.0. Since version 0.8+, you don't need to use SafeMath anymore as it is implemented on the language level.
As you are using Solidity version 0.6 you should also install the openzeppelin package for this version. This should be 3.4.1. You can install this version with the following command:
npm i #openzeppelin/contracts#3.4.1
The better solution, however, would be to update your contract to solidity version 0.8+, use the current openzeppelin implementation and remove SafeMath library.
I'm trying to fund a smart contract with LINK tokens. I get an error "VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information." My code is simple:
// SPDX-License-Identifier: MIT
pragma solidity >=0.5 <0.9.0;
//Remix Imports
import "https://github.com/smartcontractkit/chainlink/blob/develop/evm-contracts/src/v0.6/ChainlinkClient.sol";
import "https://github.com/smartcontractkit/chainlink/blob/develop/evm-contracts/src/v0.6/vendor/Ownable.sol";
import "https://github.com/smartcontractkit/chainlink/blob/develop/evm-contracts/src/v0.6/vendor/SafeMathChainlink.sol";
import "https://github.com/smartcontractkit/chainlink/blob/develop/evm-contracts/src/v0.6/interfaces/LinkTokenInterface.sol";
import "https://github.com/smartcontractkit/chainlink/blob/master/evm-contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
contract SimpleStorage {
SimpleStorage2[] simpleStorage2s;
function set() public payable returns(address) {
SimpleStorage2 a = new SimpleStorage2();
simpleStorage2s.push(a);
LinkTokenInterface link = LinkTokenInterface(a.getChainlinkToken());
link.transfer(address(a), 100);
return address(a);
}
}
contract SimpleStorage2 is ChainlinkClient, Ownable {
function getChainlinkToken() public view returns (address) {
return chainlinkTokenAddress();
}
}
Solidity compiler 0.6.12. What am I doing wrong? How do I get this to work?
Get the address of the contract that you've deployed, and send it LINK.
You can read the Chainlink documentation for more information.
It looks like you're using remix.
Get the address of your contract.
Paste it into your Metamask
3. Send your contract LINK
You'll get a few notifications to confirm.
I have an innocent looking contracts that work painlessly in Remix. Test contract can easily call Another if I use JavaScript VM in Remix.
I also have ganache-cli running on port 7454. If I connect Remix to ganache-cli, each of these contracts work well individually. But I cant call Another from Test. Remix console says transact to Test.send errored: VM Exception while processing transaction: revert
My contracts look like:
pragma solidity 0.4.25;
contract Another {
uint public balance;
function sendToAnother() public {
balance += 10;
}
}
contract Test {
function send(address another) public {
Another(another).sendToAnother();
}
}
One suspicion I have is - am I picking up the address of the Another contract correctly? I am copying it from Remix's Deployed Contracts tab.
I am using testrpc to deploy my contracts. Contract deployment is successful and it also displays the contract address in console when it is deployed.
But when I try to query from truffle console it throws this error: Contract has no network configuration for its current network id (5777).
I am clueless. Any help would be much appreciated. I am using Truffle v4.1.0-beta.0 (core: 4.1.0).
Solidity v0.4.19 (solc-js)
You need to return the the deployed contract from the Promise to have the contract object be injected by Truffle. Example:
var Caller = artifacts.require("Caller");
var Callee = artifacts.require("Callee");
module.exports = function(deployer) {
deployer.deploy(Callee).then(function() {
return deployer.deploy(Caller, Callee.address);
});
};