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

How would one muzzle a full grown polar bear in the 13th century?

Unexpected email from Yorkshire Bank

How does a DHCP relay router forward the packet to the server?

Will a top journal at least read my introduction?

Does this extra sentence in the description of the warlock's Eyes of the Rune Keeper eldritch invocation appear in any official reference?

Is thermodynamics only applicable to systems in equilibrium?

Why isn't the definition of absolute value applied when squaring a radical containing a variable?

How can I change the color of a part of a line?

How to creep the reader out with what seems like a normal person?

Mac Pro install disk keeps ejecting itself

What is the most expensive material in the world that could be used to create Pun-Pun's lute?

Sci-fi book: portals appear in London and send a failed artist towards a designated path where he operate a giant superweapon

French for 'It must be my imagination'?

Was it really necessary for the Lunar module LM to have 2 stages?

Inner for loop when run in background in bash spawns new bash process

Phrase for the opposite of "foolproof"

How can I place the product on a social media post better?

Examples of non trivial equivalence relations , I mean equivalence relations without the expression " same ... as" in their definition?

Is creating your own "experiment" considered cheating during a physics exam?

Pulling the rope with one hand is as heavy as with two hands?

Examples of subgroups where it's nontrivial to show closure under multiplication?

Please, smoke with good manners

Pressure to defend the relevance of one's area of mathematics

A Strange Latex Symbol



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













2















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.










share|improve this question
























  • 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











  • 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
















2















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.










share|improve this question
























  • 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











  • 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














2












2








2








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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











  • 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











  • 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











  • 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











1 Answer
1






active

oldest

votes


















2














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.






share|improve this answer

























  • 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












  • that's worked. Can you edit your answer so I could marked as solved.

    – user3652172
    30 mins ago












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
);



);













draft saved

draft discarded


















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









2














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.






share|improve this answer

























  • 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












  • that's worked. Can you edit your answer so I could marked as solved.

    – user3652172
    30 mins ago
















2














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.






share|improve this answer

























  • 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












  • that's worked. Can you edit your answer so I could marked as solved.

    – user3652172
    30 mins ago














2












2








2







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








edited 19 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. Try 13000000000000000000.

    – Eli Drion
    1 hour ago












  • that's worked. Can you edit your answer so I could marked as solved.

    – user3652172
    30 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











  • 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
    30 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
30 mins ago






that's worked. Can you edit your answer so I could marked as solved.

– user3652172
30 mins ago


















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Are there any AGPL-style licences that require source code modifications to be public? Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Force derivative works to be publicAre there any GPL like licenses for Apple App Store?Do you violate the GPL if you provide source code that cannot be compiled?GPL - is it distribution to use libraries in an appliance loaned to customers?Distributing App for free which uses GPL'ed codeModifications of server software under GPL, with web/CLI interfaceDoes using an AGPLv3-licensed library prevent me from dual-licensing my own source code?Can I publish only select code under GPLv3 from a private project?Is there published precedent regarding the scope of covered work that uses AGPL software?If MIT licensed code links to GPL licensed code what should be the license of the resulting binary program?If I use a public API endpoint that has its source code licensed under AGPL in my app, do I need to disclose my source?

2013 GY136 Descoberta | Órbita | Referências Menu de navegação«List Of Centaurs and Scattered-Disk Objects»«List of Known Trans-Neptunian Objects»

Button changing it's text & action. Good or terrible? The 2019 Stack Overflow Developer Survey Results Are Inchanging text on user mouseoverShould certain functions be “hard to find” for powerusers to discover?Custom liking function - do I need user login?Using different checkbox style for different checkbox behaviorBest Practices: Save and Exit in Software UIInteraction with remote validated formMore efficient UI to progress the user through a complicated process?Designing a popup notice for a gameShould bulk-editing functions be hidden until a table row is selected, or is there a better solution?Is it bad practice to disable (replace) the context menu?