I am trying to mint new token. This is part of code. On the fifth line is definition of list of four adresses,
First is contract of code which will be reward, second is router (every DEX has unique one), third is marketing wallet, fourth is dividendTracker.
Where can I have dividendTracker adress?
Thank you
constructor(
string memory name_,
string memory symbol_,
uint256 totalSupply_,
address[4] memory addrs, // reward, router, marketing wallet, dividendTracker
uint256[3] memory feeSettings, // rewards, liquidity, marketing
uint256 minimumTokenBalanceForDividends_,
address serviceFeeReceiver_,
uint256 serviceFee_
Related
I'm trying to build an external adapter for a chainlink node to import API information. On the chainlink node and API, everything seems like it worked, however when I try to call the stored value from the smart contract, it's always 0 despite the logs indicating that it ran successfully.
type = "directrequest"
schemaVersion = 1
name = "Mimi-Fund-EA"
externalJobID = "834d2179-321d-49ac-bf63-140635e3a606"
forwardingAllowed = false
maxTaskDuration = "0s"
contractAddress = "0xAf644831B57E5625ac64cDa68248b810bE4D4D01"
minContractPaymentLinkJuels = "0"
observationSource = """
decode_log [type=ethabidecodelog
abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)"
data="$(jobRun.logData)"
topics="$(jobRun.logTopics)"]
decode_cbor [type=cborparse data="$(decode_log.data)"]
fetch [type=bridge name="mimifund" requestData="{\\"id\\": $(jobSpec.externalJobID), \\"data\\": { \\"year\\": $(decode_cbor.year), \\"discount_rate\\": $(decode_cbor.discount_rate)}}"]
parse [type=jsonparse path="data,result" data="$(fetch)"]
ds_multiply [type="multiply" times=1000000000000000000]
encode_data [type=ethabiencode abi="(uint256 value)" data="{ \\"value\\": $(ds_multiply) }"]
encode_tx [type=ethabiencode
abi="fulfillOracleRequest(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes32 data)"
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}"
]
submit_tx [type=ethtx to="0xAf644831B57E5625ac64cDa68248b810bE4D4D01" data="$(encode_tx)"]
decode_log -> decode_cbor -> fetch -> parse -> ds_multiply-> encode_data -> encode_tx -> submit_tx
"""
These are the run logs from the Node. Everything compiled just fine and the values look good however, they never update in a smart contract, it's always 0.
This is my smart contract for reference.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "#chainlink/contracts/src/v0.8/ChainlinkClient.sol";
import "#chainlink/contracts/src/v0.8/ConfirmedOwner.sol";
import "#openzeppelin/contracts/utils/Strings.sol";
contract mimifundCO2 is ChainlinkClient, ConfirmedOwner {
using Chainlink for Chainlink.Request;
uint256 public volume;
bytes32 private jobId;
uint256 private fee;
event RequestVolume(bytes32 indexed requestId, uint256 volume);
/**
* #notice Initialize the link token and target oracle
*
* Goerli Testnet details:
* Link Token: 0x326C977E6efc84E512bB9C30f76E30c160eD06FB
* Oracle: 0xCC79157eb46F5624204f47AB42b3906cAA40eaB7 (Chainlink DevRel)
* jobId: ca98366cc7314957b8c012c72f05aeeb
*
*/
constructor() ConfirmedOwner(msg.sender) {
setChainlinkToken(0x326C977E6efc84E512bB9C30f76E30c160eD06FB);
setChainlinkOracle(0xAf644831B57E5625ac64cDa68248b810bE4D4D01);
jobId = "834d2179321d49acbf63140635e3a606";
fee = (1 * LINK_DIVISIBILITY) / 10; // 0,1 * 10**18 (Varies by network and job)
}
/**
* Create a Chainlink request to retrieve API response, find the target
* data, then multiply by 1000000000000000000 (to remove decimal places from data).
*/
function requestCO2PricingData(uint256 _year) public returns (bytes32 requestId) {
Chainlink.Request memory req = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
req.add('year', Strings.toString(_year)); // Chainlink nodes 1.0.0 and later support this format
req.add('discount_rate', '0.0'); // Chainlink nodes 1.0.0 and later support this format
// Sends the request
return sendChainlinkRequest(req, fee);
}
/**
* Receive the response in the form of uint256
*/
function fulfill(bytes32 _requestId, uint256 _volume) public recordChainlinkFulfillment(_requestId) {
emit RequestVolume(_requestId, _volume);
volume = _volume;
}
/**
* Allow withdraw of Link tokens from the contract
*/
function withdrawLink() public onlyOwner {
LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
require(link.transfer(msg.sender, link.balanceOf(address(this))), 'Unable to transfer');
}
}
I feel like there is some update to either my fulfill function or submit_tx that I need to update, but I am out of ideas about what to change.
I've tried changing all the parameters and both the API and chainlink node accurate update and reflect the correct input. The smart contract seems to work perfectly, it's just that calling volume in the code always returns 0 and I've got no clue what the issue is.
According to your description, Chainlink node received your request and run the job successfully, but failed to write the result back to your contract. There might be multiple reasons, but most likely something is wrong when the Chainlink node calls the function fulfillOracleRequest2 in the Operator.sol and fails to write the result back to your contract.
Please check the following:
Check if you fund your Chainlink node. You can check the balance of the chainlink node in the top right of the Chainlink node UI which is usually with port number 6688(eg. http://localhost:6688). Because the Chainlink node changes the state of the blockchain when calling the function in the contract operator, there has to be a minimum balance of ETH remaining in your Chainlink node. The solution to the issue is just to transfer some ETH(not LINK) tokens to your chainlink node address.
Check if you grant the Chainlink node permission to call function fulfillOracleRequest2 in the contract operator. Search your Chainlink node address in the blockchain explorer like etherscan, goerliscan, polygonscan, etc. and if the node has no permission to call function fulfillOracleRequest, error Fail with error 'Not authorized sender' will be thrown. The solution to the issue is to use the function setAuthorizedSenders to grant the node address permission to call the function fulfillOracleRequest2.
contract Bank {
address public admin;
constructor() {
admin = msg.sender;
}
mapping (address => uint) balance;
mapping (address => bool) AccountActive;
function closeAccount() public payable{
AccountActive[msg.sender] = false;
//trasfer all the money from an account closed to the admin
payable(admin).transfer(balance[msg.sender]);
}
function viewbalance() public view returns(uint) {
return balance[msg.sender];
}}
when inserting a value before deployment, I get this error, and if I don't do it in this way the balance is 0, why? (sorry for this noob question)
This error is because you can not use an address ether balance from a smart contract. What I mean is that a smart contract cannot transfer ether from one address to another, because it would be really dangerous.
What you can do is to transfer the msg.value, which is the ether sent as the value of the transaction.
By the way, you should check for correct indentation and symbols placement. Those can lead to errors too.
The issue is here:
payable(admin).transfer(balance[msg.sender]);
You want to transfer money from the admin but the admin has no balance. So you need to send money. For this write this function:
function depositMoneyToAdmin() payable public {
// since it is payable, the money that you send would be stored in msg.value
(bool success,) = admin.call{value: msg.value}("");
// then add the owner's balance to the mapping so when u call viewBalance, you get the balance of owner
balance[admin]+=msg.value;
require(success,"Transfer failed!");
}
Avoid using transfer.
https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/
I am playing with Ethereum smart contracts and noticed some strange behavior of some transactions.
Transaction is visible and it states that tokens are sent to an address but when I check balance on Metamask it's not here (Token contract is added to MetaMask). What could be the reason of such contract behavior?
This is example transaction: https://ropsten.etherscan.io/tx/0xf3316c497fd47ee79be57be7b91cb96cc0414003a155d8ff8bc83b3a090594c9
200,000 tokens is sent to https://ropsten.etherscan.io/address/0x9DEF8C013eb590aFf09c8c76F9A74A3055fAA177#tokentxns and it's displayed on ropsten network explorer, but I can't see them or manipulate on MetaMask.
This is part of my smart contract which does transfer, I marked line with comment "invisible" which does not work for me:
function transfer(address to, uint256 value) public returns (bool) {
require(value <= _balances[msg.sender]);
require(to != address(0));
uint256 tokensToBurn = findOnePercent(value);
uint256 tokensToStack = findOnePercent(value);
uint256 tokenstoDeduct = tokensToBurn.add(tokensToStack);
uint256 tokensToTransfer = value.sub(tokenstoDeduct);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(tokensToTransfer);
_totalSupply = _totalSupply.sub(tokenstoDeduct);
emit Transfer(msg.sender, to, tokensToTransfer); // visible on metaMask
emit Transfer(msg.sender, address(0), tokensToBurn); // burned
emit Transfer(msg.sender, address(VAULT_ADDRESS), tokensToStack); // invisible on metaMask
return true;
}
This is screenshot of address wallet: 0x9DEF8C013eb590aFf09c8c76F9A74A3055fAA177
Please advise what I could do wrong here.
[meanwhile I submitted ticket to MetaMask, maybe it's a defect on wallet extension]
You need to add the contract address to your Metamask instance.
In the account detail, click on "Add token"
Paste the conctract address to the address field in the "Custom token" tab
Review the data, click "Next", and you you can see the token balance in your wallet.
I am using the below code in solidity to transfer ether from one account to another.
I am calling this from the owner's account.
But my ether gets deducted from owners and goes to contract address instead of the receiver/payee account.
function PayCredit(address payable payee, uint money, uint invoiceNum) public payable{
require(msg.sender==owner, "only owner can invoke it");
payee.transfer(address(this).balance);
claims[payee][invoiceNum].isPayed = true;
}
You are sending your ether's to contract address , change address(this) to address .
I would suggest you good practice of sending ether's to other account. Solidity transaction support value as argument and this is good place for sending ether(WEI) to other account . below code snippet will send 12 WEI to other account.
pragma solidity >=0.4.22 <0.6.0;
contract AB {
uint256 num1;
address owner;
constructor() public{
owner = msg.sender;
}
function sendBal(address payable receiver) payable external onlyOwner {
uint256 amount = msg.value;
receiver.transfer(amount);
}
I am pretty new to Solidity and working with Ethereum in general.
In the (d)app I'm working on I need to be able to persist data onto the ledger, but I'm not sure I understand how this works.
Let's say I have the following contract (simplified for practicality):
contract UserContract {
struct User {
address walletAddress;
string organisation;
string fName;
string lName;
string email;
uint index;
}
mapping(address => User) private users;
address[] private userIndex;
function insertUser(
address walletAddress,
string organisation,
string fName,
string lName,
string email )
public
returns(uint index) {
User memory newUser = User({
walletAddress: walletAddress,
organisation: organisation,
fName: fName,
lName: lName,
email: email,
index: users.length
});
users.push(newUser);
userIndex[walletAddress] = newUser.index;
return newUser.index;
}
}
Using the insertUser() method, I can insert a new user, and using a getter method I could retrieve the user's information.
Now, if I update the contract (thus deploy a new one), the users mapping is empty again, not surprising.
My question: how do I store data in a way that it will be accessible for future versions of the contract? Any design patterns that go along with this process?
Thanks!
Since, as you know, stored data will not travel with a new contract and copying over data to a new contract would be expensive task after a few uses...your best bet is to separate functionality from data storage.
Create a contract with some basic setters and getters that only deals with data storage (from a particular contract address if necessary)...then create your main functional contract that connects to the data contract.