首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我将如何用直接从sbt换DAI的方式来交换ETH?

我将如何用直接从sbt换DAI的方式来交换ETH?
EN

Ethereum用户
提问于 2019-05-05 15:27:54
回答 1查看 696关注 0票数 3

首先,我喜欢sbt-ethereum。这是一种活泼和绝对的乐趣。在完成了教程的契约交互部分之后,我想测试一个活合同。

我想与uniswap.io的ETH交易合同直接从sbt-ethereum获得2 DAI.

  1. 我通过在dai-token上滚动找到了以太扫描地址
  2. 然后使用Uniswap文档获取uniswap-factory协议地址。
  3. 名为ethTransactionView uniswap-factory getExchange dai-token
  4. 这将返回uniswap-dai-exchange地址(0x09cabec1ead1c0ba254b09efb3ee13841712be14)
  5. 我验证了合同ABI 关于以太扫描是否与github版本匹配。
  6. 然后我试着用5分钟的计时器得到两个戴。不同的输入参数组合(请参阅A到E),包括一些带有[ETH to pay, optional]字段的输入参数组合,在相同的错误情况下失败。
  7. 我检查了dai合同,它似乎是18个小数,所以我把DAI的输入改为2e18。我尝试了以太和芬尼面额的可选付款方式。我还使用了ethToTokenSwapInput,指定了ETH的数量,而不是DAI,同样的结果。

所需com.mchange.sc.v2.jsonrpc.package$JsonrpcException:气体超过允许量或交易总是失败:没有进一步的信息

我肯定这是我做的很简单的事情。寄出的钱夹由价值超过5 DAI的ETH资助。

Any想法?

注意:我无法将新的sbt-ethereum标记按原计划创建为声誉<150。

答:ethTransactionInvoke uniswap-dai-exchange ethToTokenSwapOutput 2 300

B:ethTransactionInvoke uniswap-dai-exchange ethToTokenSwapOutput 2 300 15 finney

C:ethTransactionInvoke uniswap-dai-exchange ethToTokenSwapOutput 2000000000000000000 300

D:ethTransactionInvoke uniswap-dai-exchange ethToTokenSwapOutput 2000000000000000000 300 15 finney

E:ethTransactionInvoke uniswap-dai-exchange ethToTokenSwapOutput 2000000000000000000 300 0.015 ether

EN

回答 1

Ethereum用户

回答已采纳

发布于 2019-05-06 02:31:05

首先,感谢您尝试了sbt-ethereum (并且喜欢它!)。

我想我可以做你想做的交易。有两个问题:

  1. 正如@Ismael所说,截止日期应该是unix时间戳。(考虑到这些方法的流行程度,我可能应该添加一个实用程序,以便在sbt-ethereum中轻松地计算它们。)
  2. 函数的调用。被标记为@payable,并且确实需要支付您愿意为交换提供的乙醚的数量。在我看来,sbt-ethereum教程没有很好地强调这一点,但是在调用payable函数时,在提供函数参数之后,您可以提供希望作为一个数字和单位支付的金额。(更新:我看到您已经注意到并尝试了!因此,这基本上只是最后期限。

另一个问题是戴小数是18,所以如果我们只想要2个DAI代币,我们需要2加一个0。( uint解析器在sbt-ethereum中不支持科学表示法,这是另一件需要纠正的事情!)

所以,当一切都说好了,我们就有了.

代码语言:javascript
复制
> ethTransactionInvoke unverified-uniswap-dai-exchange ethToTokenSwapOutput 2000000000000000000 1557109479 0.015 ether
[info] Unlocking address '0x465e79b940bc2157e4259ff6b2d92f454497f1e4' (on chain with ID 1, aliases ['default-sender','testing0'])
Enter passphrase or hex private key for address '0x465e79b940bc2157e4259ff6b2d92f454497f1e4': *******************
[info] V3 wallet(s) found for '0x465e79b940bc2157e4259ff6b2d92f454497f1e4' (aliases ['default-sender','testing0'])

==> T R A N S A C T I O N   S U B M I S S I O N   R E Q U E S T
==>
==> The transaction would be a message with...
==>   To:    0x09cabec1ead1c0ba254b09efb3ee13841712be14 (with aliases ['unverified-uniswap-dai-exchange'] on chain with ID 1)
==>   From:  0x465e79b940bc2157e4259ff6b2d92f454497f1e4 (with aliases ['default-sender','testing0'] on chain with ID 1)
==>   Data:  0x6b1d4db70000000000000000000000000000000000000000000000001bc16d674ec80000000000000000000000000000000000000000000000000000000000005ccf9ae7
==>   Value: 0.015 Ether
==>
==> The transaction is signed with Chain ID 1 (which correctly matches the current session's 'ethNodeChainId').
==>
==> According to the ABI currently associated with the 'to' address, this message would amount to the following method call...
==>   Function called: ethToTokenSwapOutput(uint256,uint256)
==>     Arg 1 [name=tokens_bought, type=uint256]: 2000000000000000000
==>     Arg 2 [name=deadline, type=uint256]: 1557109479
==>
==> The nonce of the transaction would be 407.
==>
==> $$ The transaction you have requested could use up to 66235 units of gas.
==> $$ You would pay 3 gwei for each unit of gas, for a maximum cost of 0.000198705 ether.
==> $$ This is worth 0.031652712975 USD (according to Coinbase at 7:20 PM).
==> $$ You would also send 0.015 ether (2.389425 USD), for a maximum total cost of 0.015198705 ether (2.421077712975 USD).

Would you like to submit this transaction? [y/n] y
A transaction with hash '0x0509bafc336c760f21e6c7a1c491d7ba86a6c17c18ec46eec8d87d4995afd8e6' will be submitted. Please wait.
[info] Called function 'ethToTokenSwapOutput', with args '2000000000000000000, 1557109479', sending 15000000000000000 wei to address '0x09cabec1ead1c0ba254b09efb3ee13841712be14' in transaction '0x0509bafc336c760f21e6c7a1c491d7ba86a6c17c18ec46eec8d87d4995afd8e6'.
[info] Waiting for the transaction to be mined (will wait up to 5 minutes).
[info] Transaction Receipt:
[info]        Transaction Hash:    0x0509bafc336c760f21e6c7a1c491d7ba86a6c17c18ec46eec8d87d4995afd8e6
[info]        Transaction Index:   122
[info]        Transaction Status:  SUCCEEDED
[info]        Block Hash:          0x3257d8fd31b49c2c7d55d72c0fddd01f02b92a3326529ed903fdd0e6cb520f9d
[info]        Block Number:        7704627
[info]        From:                0x465e79b940bc2157e4259ff6b2d92f454497f1e4
[info]        To:                  0x09cabec1ead1c0ba254b09efb3ee13841712be14
[info]        Cumulative Gas Used: 6482478
[info]        Gas Used:            54719
[info]        Contract Address:    None
[info]        Logs:                0 => EthLogEntry [source=0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359] (
[info]                                    topics=[
[info]                                      0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef,
[info]                                      0x00000000000000000000000009cabec1ead1c0ba254b09efb3ee13841712be14,
[info]                                      0x000000000000000000000000465e79b940bc2157e4259ff6b2d92f454497f1e4
[info]                                    ],
[info]                                    data=0000000000000000000000000000000000000000000000001bc16d674ec80000
[info]                                  ),
[info]                             1 => EthLogEntry [source=0x09cabec1ead1c0ba254b09efb3ee13841712be14] (
[info]                                    topics=[
[info]                                      0xcd60aa75dea3072fbc07ae6d7d856b5dc5f4eee88854f5b4abf7b680ef8bc50f,
[info]                                      0x000000000000000000000000465e79b940bc2157e4259ff6b2d92f454497f1e4,
[info]                                      0x000000000000000000000000000000000000000000000000002c13f43dbb6c42,
[info]                                      0x0000000000000000000000000000000000000000000000001bc16d674ec80000
[info]                                    ],
[info]                                    data=
[info]                                  )
[info]        Events:              0 => Transfer [source=0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359] (
[info]                                    _from (of type address): 0x09cabec1ead1c0ba254b09efb3ee13841712be14,
[info]                                    _to (of type address): 0x465e79b940bc2157e4259ff6b2d92f454497f1e4,
[info]                                    _value (of type uint256): 2000000000000000000
[info]                                  ),
[info]                             1 => TokenPurchase [source=0x09cabec1ead1c0ba254b09efb3ee13841712be14] (
[info]                                    buyer (of type address): 0x465e79b940bc2157e4259ff6b2d92f454497f1e4,
[info]                                    eth_sold (of type uint256): 12406838703909954,
[info]                                    tokens_bought (of type uint256): 2000000000000000000
[info]                                  )
[success] Total time: 37 s, completed May 5, 2019 7:20:27 PM

sbt:ethdocstore> ethTransactionView 0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359 balanceOf testing0
[info] The function 'balanceOf' yields 1 result.
[info]  + Result 1 of type 'uint256', named 'balance', is 2000000000000000002
[success] Total time: 1 s, completed May 5, 2019 7:26:36 PM

帐户余额末尾的额外2个原子是由于我最初的尝试,而不是所有这些额外的零。

您可以看到,如果您检查成功的交易,对于我的2 DAI我发送了0.015 ether,但是(在一个“内部事务”)得到0.002593161296090046 ether作为改变。

再次感谢你给sbt-ethereum一次机会。我希望这能帮到你!

附注:如果您想在sbt-ethereum中计算300秒(5分钟)的最后期限,您可以这样做。

代码语言:javascript
复制
> consoleQuick
[info] Starting scala interpreter...
Welcome to Scala 2.12.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_172).
Type in expressions for evaluation. Or try :help.

scala> (System.currentTimeMillis / 1000) + 300
res0: Long = 1557110378

scala> 

显然,最好不要掉进Scala来完成这个任务。

票数 2
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/70408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档