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
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 toERC20
since the type ofBAT_TOKEN_ADDRESS
is alreadyERC20
, and it doesn't look like you need thepayable
either.
– goodvibration
2 hours ago
BTW, are you sure that there's a contract which implements yourERC20
interface 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 toERC20
since the type ofBAT_TOKEN_ADDRESS
is alreadyERC20
, and it doesn't look like you need thepayable
either.
– goodvibration
2 hours ago
BTW, are you sure that there's a contract which implements yourERC20
interface 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 toERC20
since the type ofBAT_TOKEN_ADDRESS
is alreadyERC20
, and it doesn't look like you need thepayable
either.
– goodvibration
2 hours ago
BTW, are you sure that there's a contract which implements yourERC20
interface 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
30 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
30 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
30 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 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. Try13000000000000000000
.
– Eli Drion
1 hour ago
that's worked. Can you edit your answer so I could marked as solved.
– user3652172
30 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
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
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
ERC20
since the type ofBAT_TOKEN_ADDRESS
is alreadyERC20
, and it doesn't look like you need thepayable
either.– goodvibration
2 hours ago
BTW, are you sure that there's a contract which implements your
ERC20
interface 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