Can you send a token and get ether back?
up vote
1
down vote
favorite
If a user sends a token, let's call it ABC
, to the contract that issued that token, can the contract send back ether to the user?
solidity tokens
New contributor
add a comment |
up vote
1
down vote
favorite
If a user sends a token, let's call it ABC
, to the contract that issued that token, can the contract send back ether to the user?
solidity tokens
New contributor
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
If a user sends a token, let's call it ABC
, to the contract that issued that token, can the contract send back ether to the user?
solidity tokens
New contributor
If a user sends a token, let's call it ABC
, to the contract that issued that token, can the contract send back ether to the user?
solidity tokens
solidity tokens
New contributor
New contributor
edited 2 days ago
PaulRBerg
1,017319
1,017319
New contributor
asked 2 days ago
chrisfuture
61
61
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
Yes, for example:
contract ABCToken {
function sell(uint abcAmount) public {
uint ethAmount = myFunc(abcAmount);
msg.sender.transfer(ethAmount);
}
}
Of course, you probably want to make sure that this user (msg.sender
) owns the specified amount of ABC tokens...
add a comment |
up vote
1
down vote
Adding to goodVibration's answer, you want to make sure the user actually sent what they say they sent.
contract ABCToken {
function sell(uint abcAmount) public {
require(token.transferFrom(msg.sender, address(this), abcAmount));
uint ethAmount = myFunc(abcAmount);
msg.sender.transfer(ethAmount);
}
}
Transfer from requires the sender to first send an approve()
to the token contract to set an allowance the above function can use to retrieve the user's tokens. The 2-step process is usually coordinated client-side or in another contract.
Hope it helps.
1
Thanks. Risk of scribbling it up freestyle. Fixed.
– Rob Hitchens B9lab
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Yes, for example:
contract ABCToken {
function sell(uint abcAmount) public {
uint ethAmount = myFunc(abcAmount);
msg.sender.transfer(ethAmount);
}
}
Of course, you probably want to make sure that this user (msg.sender
) owns the specified amount of ABC tokens...
add a comment |
up vote
1
down vote
Yes, for example:
contract ABCToken {
function sell(uint abcAmount) public {
uint ethAmount = myFunc(abcAmount);
msg.sender.transfer(ethAmount);
}
}
Of course, you probably want to make sure that this user (msg.sender
) owns the specified amount of ABC tokens...
add a comment |
up vote
1
down vote
up vote
1
down vote
Yes, for example:
contract ABCToken {
function sell(uint abcAmount) public {
uint ethAmount = myFunc(abcAmount);
msg.sender.transfer(ethAmount);
}
}
Of course, you probably want to make sure that this user (msg.sender
) owns the specified amount of ABC tokens...
Yes, for example:
contract ABCToken {
function sell(uint abcAmount) public {
uint ethAmount = myFunc(abcAmount);
msg.sender.transfer(ethAmount);
}
}
Of course, you probably want to make sure that this user (msg.sender
) owns the specified amount of ABC tokens...
answered 2 days ago
goodvibration
2,189721
2,189721
add a comment |
add a comment |
up vote
1
down vote
Adding to goodVibration's answer, you want to make sure the user actually sent what they say they sent.
contract ABCToken {
function sell(uint abcAmount) public {
require(token.transferFrom(msg.sender, address(this), abcAmount));
uint ethAmount = myFunc(abcAmount);
msg.sender.transfer(ethAmount);
}
}
Transfer from requires the sender to first send an approve()
to the token contract to set an allowance the above function can use to retrieve the user's tokens. The 2-step process is usually coordinated client-side or in another contract.
Hope it helps.
1
Thanks. Risk of scribbling it up freestyle. Fixed.
– Rob Hitchens B9lab
2 days ago
add a comment |
up vote
1
down vote
Adding to goodVibration's answer, you want to make sure the user actually sent what they say they sent.
contract ABCToken {
function sell(uint abcAmount) public {
require(token.transferFrom(msg.sender, address(this), abcAmount));
uint ethAmount = myFunc(abcAmount);
msg.sender.transfer(ethAmount);
}
}
Transfer from requires the sender to first send an approve()
to the token contract to set an allowance the above function can use to retrieve the user's tokens. The 2-step process is usually coordinated client-side or in another contract.
Hope it helps.
1
Thanks. Risk of scribbling it up freestyle. Fixed.
– Rob Hitchens B9lab
2 days ago
add a comment |
up vote
1
down vote
up vote
1
down vote
Adding to goodVibration's answer, you want to make sure the user actually sent what they say they sent.
contract ABCToken {
function sell(uint abcAmount) public {
require(token.transferFrom(msg.sender, address(this), abcAmount));
uint ethAmount = myFunc(abcAmount);
msg.sender.transfer(ethAmount);
}
}
Transfer from requires the sender to first send an approve()
to the token contract to set an allowance the above function can use to retrieve the user's tokens. The 2-step process is usually coordinated client-side or in another contract.
Hope it helps.
Adding to goodVibration's answer, you want to make sure the user actually sent what they say they sent.
contract ABCToken {
function sell(uint abcAmount) public {
require(token.transferFrom(msg.sender, address(this), abcAmount));
uint ethAmount = myFunc(abcAmount);
msg.sender.transfer(ethAmount);
}
}
Transfer from requires the sender to first send an approve()
to the token contract to set an allowance the above function can use to retrieve the user's tokens. The 2-step process is usually coordinated client-side or in another contract.
Hope it helps.
edited 2 days ago
answered 2 days ago
Rob Hitchens B9lab
24.3k53875
24.3k53875
1
Thanks. Risk of scribbling it up freestyle. Fixed.
– Rob Hitchens B9lab
2 days ago
add a comment |
1
Thanks. Risk of scribbling it up freestyle. Fixed.
– Rob Hitchens B9lab
2 days ago
1
1
Thanks. Risk of scribbling it up freestyle. Fixed.
– Rob Hitchens B9lab
2 days ago
Thanks. Risk of scribbling it up freestyle. Fixed.
– Rob Hitchens B9lab
2 days ago
add a comment |
chrisfuture is a new contributor. Be nice, and check out our Code of Conduct.
chrisfuture is a new contributor. Be nice, and check out our Code of Conduct.
chrisfuture is a new contributor. Be nice, and check out our Code of Conduct.
chrisfuture is a new contributor. Be nice, and check out our Code of Conduct.
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
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f62176%2fcan-you-send-a-token-and-get-ether-back%23new-answer', 'question_page');
}
);
Post as a guest
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
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
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