How to interact with ERC20 interface?API to “Read Contract Information” to fetch stats of an ICOSmart contract erc20 code snippet to prevent buyer token transfersHow to input multiple arguments in remix?This contract does not implement all functions and thus cannot be createdWhat is the format for sending erc20 token to multiple address?Assertion Rely on Balance AmountsHow is gas adjusted for a transfer in solidity?remix ERC223: This contract does not implement all functions and thus cannot be createdCompile source code error expected pragmaVerify & Publish Contract Source Code
Does this extra sentence in the description of the warlock's Eyes of the Rune Keeper eldritch invocation appear in any official reference?
Providence Pentominoes Puzzle By Andrew Bradburn (Jigsaw)
Why is current rating for multicore cable lower than single core with the same cross section?
Was there a Viking Exchange as well as a Columbian one?
Disable screen dimming in Ubuntu Mate 18.04.2 LTS
function to receive a character input and return date format (with incorrect input)
Confused by chemical notation
how to interpret this t result?
How can I place the product on a social media post better?
What's the polite way to say "I need to urinate"?
What is the most expensive material in the world that could be used to create Pun-Pun's lute?
Hilbert Space and Banach Space
Minimum value of 4 digit number divided by sum of its digits
Can someone publish a story that happened to you?
How come there are so many candidates for the 2020 Democratic party presidential nomination?
A Strange Latex Symbol
Rivers without rain
Single SMS won't delete from Messaging app
Who is the Umpire in this picture?
How to figure out whether the data is sample data or population data apart from the client's information?
Will this character get back his Infinity Stone?
Who and which - What to choose when we are referring to a choice between two or more things or persons
A Note on N!
Any examples of headwear for races with animal ears?
How to interact with ERC20 interface?
API to “Read Contract Information” to fetch stats of an ICOSmart contract erc20 code snippet to prevent buyer token transfersHow to input multiple arguments in remix?This contract does not implement all functions and thus cannot be createdWhat is the format for sending erc20 token to multiple address?Assertion Rely on Balance AmountsHow is gas adjusted for a transfer in solidity?remix ERC223: This contract does not implement all functions and thus cannot be createdCompile source code error expected pragmaVerify & Publish Contract Source Code
My target is to send from the ERC20Wrapper.sol deployed contract BAT tokens to my hard coded address.
I've created ERC20 Interface:
pragma solidity 0.4.18;
interface ERC20
function totalSupply() public view returns (uint supply);
function balanceOf(address _owner) public view returns (uint balance);
function transfer(address _to, uint _value) public returns (bool success);
function transferFrom(address _from, address _to, uint _value) public returns (bool success);
function approve(address _spender, uint _value) public returns (bool success);
function allowance(address _owner, address _spender) public view returns (uint remaining);
function decimals() public view returns(uint digits);
event Approval(address indexed _owner, address indexed _spender, uint _value);
Then I Added ERC20Wrapper.sol:
pragma solidity ^0.4.18;
import "./ERC20Interface.sol";
contract ERC20Wrapper
ERC20 constant internal BAT_TOKEN_ADDRESS = ERC20(0xDb0040451F373949A4Be60dcd7b6B8D6E42658B6);
address myAddress = address(0xAD53363200C71751FA325ED7bE483722256C3501);
function BATSend(uint tokenAmount) public payable
ERC20(BAT_TOKEN_ADDRESS).transfer(myAddress,tokenAmount);
Then I instantiate ERC20Wrapper.sol and got its address on Remix, sent to the newly created contract addrees 200 BAT tokens and tried to interact with BATSend by calling transfer on ERC20 interface and entered 20 in the tokenAmount parameter.
Expected output, my account will have +=tokenAmount and it didn't happened, tx was confirmed and account amount didn't changed.
solidity erc-20 interfaces
add a comment |
My target is to send from the ERC20Wrapper.sol deployed contract BAT tokens to my hard coded address.
I've created ERC20 Interface:
pragma solidity 0.4.18;
interface ERC20
function totalSupply() public view returns (uint supply);
function balanceOf(address _owner) public view returns (uint balance);
function transfer(address _to, uint _value) public returns (bool success);
function transferFrom(address _from, address _to, uint _value) public returns (bool success);
function approve(address _spender, uint _value) public returns (bool success);
function allowance(address _owner, address _spender) public view returns (uint remaining);
function decimals() public view returns(uint digits);
event Approval(address indexed _owner, address indexed _spender, uint _value);
Then I Added ERC20Wrapper.sol:
pragma solidity ^0.4.18;
import "./ERC20Interface.sol";
contract ERC20Wrapper
ERC20 constant internal BAT_TOKEN_ADDRESS = ERC20(0xDb0040451F373949A4Be60dcd7b6B8D6E42658B6);
address myAddress = address(0xAD53363200C71751FA325ED7bE483722256C3501);
function BATSend(uint tokenAmount) public payable
ERC20(BAT_TOKEN_ADDRESS).transfer(myAddress,tokenAmount);
Then I instantiate ERC20Wrapper.sol and got its address on Remix, sent to the newly created contract addrees 200 BAT tokens and tried to interact with BATSend by calling transfer on ERC20 interface and entered 20 in the tokenAmount parameter.
Expected output, my account will have +=tokenAmount and it didn't happened, tx was confirmed and account amount didn't changed.
solidity erc-20 interfaces
Well what DID happen???
– goodvibration
2 hours ago
P.S.: You don't need the cast toERC20since the type ofBAT_TOKEN_ADDRESSis alreadyERC20, and it doesn't look like you need thepayableeither.
– goodvibration
2 hours ago
BTW, are you sure that there's a contract which implements yourERC20interface deployed at address0xDb0040451F373949A4Be60dcd7b6B8D6E42658B6?
– goodvibration
2 hours ago
Yes, plus I instantiate BAT token address with ERC20 interface to check the balance of the contract address which I've send the BAT tokens to and for the balanceOf(createdContract) I got balance 200000000000000000000. and when I tried to send 13 on BATSend it tx was confirmed and still no change to myAddress.
– user3652172
1 hour ago
add a comment |
My target is to send from the ERC20Wrapper.sol deployed contract BAT tokens to my hard coded address.
I've created ERC20 Interface:
pragma solidity 0.4.18;
interface ERC20
function totalSupply() public view returns (uint supply);
function balanceOf(address _owner) public view returns (uint balance);
function transfer(address _to, uint _value) public returns (bool success);
function transferFrom(address _from, address _to, uint _value) public returns (bool success);
function approve(address _spender, uint _value) public returns (bool success);
function allowance(address _owner, address _spender) public view returns (uint remaining);
function decimals() public view returns(uint digits);
event Approval(address indexed _owner, address indexed _spender, uint _value);
Then I Added ERC20Wrapper.sol:
pragma solidity ^0.4.18;
import "./ERC20Interface.sol";
contract ERC20Wrapper
ERC20 constant internal BAT_TOKEN_ADDRESS = ERC20(0xDb0040451F373949A4Be60dcd7b6B8D6E42658B6);
address myAddress = address(0xAD53363200C71751FA325ED7bE483722256C3501);
function BATSend(uint tokenAmount) public payable
ERC20(BAT_TOKEN_ADDRESS).transfer(myAddress,tokenAmount);
Then I instantiate ERC20Wrapper.sol and got its address on Remix, sent to the newly created contract addrees 200 BAT tokens and tried to interact with BATSend by calling transfer on ERC20 interface and entered 20 in the tokenAmount parameter.
Expected output, my account will have +=tokenAmount and it didn't happened, tx was confirmed and account amount didn't changed.
solidity erc-20 interfaces
My target is to send from the ERC20Wrapper.sol deployed contract BAT tokens to my hard coded address.
I've created ERC20 Interface:
pragma solidity 0.4.18;
interface ERC20
function totalSupply() public view returns (uint supply);
function balanceOf(address _owner) public view returns (uint balance);
function transfer(address _to, uint _value) public returns (bool success);
function transferFrom(address _from, address _to, uint _value) public returns (bool success);
function approve(address _spender, uint _value) public returns (bool success);
function allowance(address _owner, address _spender) public view returns (uint remaining);
function decimals() public view returns(uint digits);
event Approval(address indexed _owner, address indexed _spender, uint _value);
Then I Added ERC20Wrapper.sol:
pragma solidity ^0.4.18;
import "./ERC20Interface.sol";
contract ERC20Wrapper
ERC20 constant internal BAT_TOKEN_ADDRESS = ERC20(0xDb0040451F373949A4Be60dcd7b6B8D6E42658B6);
address myAddress = address(0xAD53363200C71751FA325ED7bE483722256C3501);
function BATSend(uint tokenAmount) public payable
ERC20(BAT_TOKEN_ADDRESS).transfer(myAddress,tokenAmount);
Then I instantiate ERC20Wrapper.sol and got its address on Remix, sent to the newly created contract addrees 200 BAT tokens and tried to interact with BATSend by calling transfer on ERC20 interface and entered 20 in the tokenAmount parameter.
Expected output, my account will have +=tokenAmount and it didn't happened, tx was confirmed and account amount didn't changed.
solidity erc-20 interfaces
solidity erc-20 interfaces
edited 2 hours ago
user3652172
asked 2 hours ago
user3652172user3652172
154
154
Well what DID happen???
– goodvibration
2 hours ago
P.S.: You don't need the cast toERC20since the type ofBAT_TOKEN_ADDRESSis alreadyERC20, and it doesn't look like you need thepayableeither.
– goodvibration
2 hours ago
BTW, are you sure that there's a contract which implements yourERC20interface deployed at address0xDb0040451F373949A4Be60dcd7b6B8D6E42658B6?
– goodvibration
2 hours ago
Yes, plus I instantiate BAT token address with ERC20 interface to check the balance of the contract address which I've send the BAT tokens to and for the balanceOf(createdContract) I got balance 200000000000000000000. and when I tried to send 13 on BATSend it tx was confirmed and still no change to myAddress.
– user3652172
1 hour ago
add a comment |
Well what DID happen???
– goodvibration
2 hours ago
P.S.: You don't need the cast toERC20since the type ofBAT_TOKEN_ADDRESSis alreadyERC20, and it doesn't look like you need thepayableeither.
– goodvibration
2 hours ago
BTW, are you sure that there's a contract which implements yourERC20interface deployed at address0xDb0040451F373949A4Be60dcd7b6B8D6E42658B6?
– goodvibration
2 hours ago
Yes, plus I instantiate BAT token address with ERC20 interface to check the balance of the contract address which I've send the BAT tokens to and for the balanceOf(createdContract) I got balance 200000000000000000000. and when I tried to send 13 on BATSend it tx was confirmed and still no change to myAddress.
– user3652172
1 hour ago
Well what DID happen???
– goodvibration
2 hours ago
Well what DID happen???
– goodvibration
2 hours ago
P.S.: You don't need the cast to
ERC20 since the type of BAT_TOKEN_ADDRESS is already ERC20, and it doesn't look like you need the payable either.– goodvibration
2 hours ago
P.S.: You don't need the cast to
ERC20 since the type of BAT_TOKEN_ADDRESS is already ERC20, and it doesn't look like you need the payable either.– goodvibration
2 hours ago
BTW, are you sure that there's a contract which implements your
ERC20 interface deployed at address 0xDb0040451F373949A4Be60dcd7b6B8D6E42658B6?– goodvibration
2 hours ago
BTW, are you sure that there's a contract which implements your
ERC20 interface deployed at address 0xDb0040451F373949A4Be60dcd7b6B8D6E42658B6?– goodvibration
2 hours ago
Yes, plus I instantiate BAT token address with ERC20 interface to check the balance of the contract address which I've send the BAT tokens to and for the balanceOf(createdContract) I got balance 200000000000000000000. and when I tried to send 13 on BATSend it tx was confirmed and still no change to myAddress.
– user3652172
1 hour ago
Yes, plus I instantiate BAT token address with ERC20 interface to check the balance of the contract address which I've send the BAT tokens to and for the balanceOf(createdContract) I got balance 200000000000000000000. and when I tried to send 13 on BATSend it tx was confirmed and still no change to myAddress.
– user3652172
1 hour ago
add a comment |
1 Answer
1
active
oldest
votes
First, as pointed by @goodvibration, you don't need to recast BAT_TOKEN_ADDRESS to the ERC20 interface since you already did it when assigning its value.
Second, your BATSend function should check whether the tokens transfer was successful or not since transfer returns a boolean (true if the transfer was successful, false otherwise), like that :
function BATSend(uint tokenAmount) public payable
require(ERC20(BAT_TOKEN_ADDRESS).transfer(myAddress,tokenAmount));
Now, concerning your balance not being increased, it's probably because your contract's balance is empty, or inferior to the amount of tokens you are trying to transfer.
Whenever you transfer tokens, you should be aware of how many decimals the ERC20 uses. In your case, BAT uses 18 decimals, so you should multiply the amounts of tokens you want to send by 1e18.
edited the ERC20Wrapper.sol and added the require, made sure the balanceOf newly created contract address was changed when I've send BAT to it - balance 200000000000000000000. still no change when I tried to use BATSend with amount of 13, tx was confirmed and no change to myAddress balance.
– user3652172
1 hour ago
The amount should be in wei. By inputting just 13, you are actually sending 0.00...013 BAT, it's peanuts. Try13000000000000000000.
– Eli Drion
1 hour ago
that's worked. Can you edit your answer so I could marked as solved.
– user3652172
39 mins ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "642"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f70155%2fhow-to-interact-with-erc20-interface%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
First, as pointed by @goodvibration, you don't need to recast BAT_TOKEN_ADDRESS to the ERC20 interface since you already did it when assigning its value.
Second, your BATSend function should check whether the tokens transfer was successful or not since transfer returns a boolean (true if the transfer was successful, false otherwise), like that :
function BATSend(uint tokenAmount) public payable
require(ERC20(BAT_TOKEN_ADDRESS).transfer(myAddress,tokenAmount));
Now, concerning your balance not being increased, it's probably because your contract's balance is empty, or inferior to the amount of tokens you are trying to transfer.
Whenever you transfer tokens, you should be aware of how many decimals the ERC20 uses. In your case, BAT uses 18 decimals, so you should multiply the amounts of tokens you want to send by 1e18.
edited the ERC20Wrapper.sol and added the require, made sure the balanceOf newly created contract address was changed when I've send BAT to it - balance 200000000000000000000. still no change when I tried to use BATSend with amount of 13, tx was confirmed and no change to myAddress balance.
– user3652172
1 hour ago
The amount should be in wei. By inputting just 13, you are actually sending 0.00...013 BAT, it's peanuts. Try13000000000000000000.
– Eli Drion
1 hour ago
that's worked. Can you edit your answer so I could marked as solved.
– user3652172
39 mins ago
add a comment |
First, as pointed by @goodvibration, you don't need to recast BAT_TOKEN_ADDRESS to the ERC20 interface since you already did it when assigning its value.
Second, your BATSend function should check whether the tokens transfer was successful or not since transfer returns a boolean (true if the transfer was successful, false otherwise), like that :
function BATSend(uint tokenAmount) public payable
require(ERC20(BAT_TOKEN_ADDRESS).transfer(myAddress,tokenAmount));
Now, concerning your balance not being increased, it's probably because your contract's balance is empty, or inferior to the amount of tokens you are trying to transfer.
Whenever you transfer tokens, you should be aware of how many decimals the ERC20 uses. In your case, BAT uses 18 decimals, so you should multiply the amounts of tokens you want to send by 1e18.
edited the ERC20Wrapper.sol and added the require, made sure the balanceOf newly created contract address was changed when I've send BAT to it - balance 200000000000000000000. still no change when I tried to use BATSend with amount of 13, tx was confirmed and no change to myAddress balance.
– user3652172
1 hour ago
The amount should be in wei. By inputting just 13, you are actually sending 0.00...013 BAT, it's peanuts. Try13000000000000000000.
– Eli Drion
1 hour ago
that's worked. Can you edit your answer so I could marked as solved.
– user3652172
39 mins ago
add a comment |
First, as pointed by @goodvibration, you don't need to recast BAT_TOKEN_ADDRESS to the ERC20 interface since you already did it when assigning its value.
Second, your BATSend function should check whether the tokens transfer was successful or not since transfer returns a boolean (true if the transfer was successful, false otherwise), like that :
function BATSend(uint tokenAmount) public payable
require(ERC20(BAT_TOKEN_ADDRESS).transfer(myAddress,tokenAmount));
Now, concerning your balance not being increased, it's probably because your contract's balance is empty, or inferior to the amount of tokens you are trying to transfer.
Whenever you transfer tokens, you should be aware of how many decimals the ERC20 uses. In your case, BAT uses 18 decimals, so you should multiply the amounts of tokens you want to send by 1e18.
First, as pointed by @goodvibration, you don't need to recast BAT_TOKEN_ADDRESS to the ERC20 interface since you already did it when assigning its value.
Second, your BATSend function should check whether the tokens transfer was successful or not since transfer returns a boolean (true if the transfer was successful, false otherwise), like that :
function BATSend(uint tokenAmount) public payable
require(ERC20(BAT_TOKEN_ADDRESS).transfer(myAddress,tokenAmount));
Now, concerning your balance not being increased, it's probably because your contract's balance is empty, or inferior to the amount of tokens you are trying to transfer.
Whenever you transfer tokens, you should be aware of how many decimals the ERC20 uses. In your case, BAT uses 18 decimals, so you should multiply the amounts of tokens you want to send by 1e18.
edited 27 mins ago
answered 1 hour ago
Eli DrionEli Drion
2,101214
2,101214
edited the ERC20Wrapper.sol and added the require, made sure the balanceOf newly created contract address was changed when I've send BAT to it - balance 200000000000000000000. still no change when I tried to use BATSend with amount of 13, tx was confirmed and no change to myAddress balance.
– user3652172
1 hour ago
The amount should be in wei. By inputting just 13, you are actually sending 0.00...013 BAT, it's peanuts. Try13000000000000000000.
– Eli Drion
1 hour ago
that's worked. Can you edit your answer so I could marked as solved.
– user3652172
39 mins ago
add a comment |
edited the ERC20Wrapper.sol and added the require, made sure the balanceOf newly created contract address was changed when I've send BAT to it - balance 200000000000000000000. still no change when I tried to use BATSend with amount of 13, tx was confirmed and no change to myAddress balance.
– user3652172
1 hour ago
The amount should be in wei. By inputting just 13, you are actually sending 0.00...013 BAT, it's peanuts. Try13000000000000000000.
– Eli Drion
1 hour ago
that's worked. Can you edit your answer so I could marked as solved.
– user3652172
39 mins ago
edited the ERC20Wrapper.sol and added the require, made sure the balanceOf newly created contract address was changed when I've send BAT to it - balance 200000000000000000000. still no change when I tried to use BATSend with amount of 13, tx was confirmed and no change to myAddress balance.
– user3652172
1 hour ago
edited the ERC20Wrapper.sol and added the require, made sure the balanceOf newly created contract address was changed when I've send BAT to it - balance 200000000000000000000. still no change when I tried to use BATSend with amount of 13, tx was confirmed and no change to myAddress balance.
– user3652172
1 hour ago
The amount should be in wei. By inputting just 13, you are actually sending 0.00...013 BAT, it's peanuts. Try
13000000000000000000.– Eli Drion
1 hour ago
The amount should be in wei. By inputting just 13, you are actually sending 0.00...013 BAT, it's peanuts. Try
13000000000000000000.– Eli Drion
1 hour ago
that's worked. Can you edit your answer so I could marked as solved.
– user3652172
39 mins ago
that's worked. Can you edit your answer so I could marked as solved.
– user3652172
39 mins ago
add a comment |
Thanks for contributing an answer to Ethereum Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f70155%2fhow-to-interact-with-erc20-interface%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Well what DID happen???
– goodvibration
2 hours ago
P.S.: You don't need the cast to
ERC20since the type ofBAT_TOKEN_ADDRESSis alreadyERC20, and it doesn't look like you need thepayableeither.– goodvibration
2 hours ago
BTW, are you sure that there's a contract which implements your
ERC20interface deployed at address0xDb0040451F373949A4Be60dcd7b6B8D6E42658B6?– goodvibration
2 hours ago
Yes, plus I instantiate BAT token address with ERC20 interface to check the balance of the contract address which I've send the BAT tokens to and for the balanceOf(createdContract) I got balance 200000000000000000000. and when I tried to send 13 on BATSend it tx was confirmed and still no change to myAddress.
– user3652172
1 hour ago