如何从智能合同中提取以太坊
我是区块链技术的新手,我有疑问。 我刚刚向Rinkeby TestNet网络部署了一份以太坊智能合约,并铸造了一些NFT。在rinkeby.etherscan.io上检查我的合同地址时,我可以看到智能合约的余额。
问题是,如何将这些以太坊在智能合同平衡中转移到我的钱包中。既然我是所有者,我应该以某种方式收到这些ETH,以某种方式进入我的MetAmask钱包?
智能合约包括以下功能
// This will transfer the remaining contract balance to the owner.
// Do not remove this otherwise you will not be able to withdraw the funds.
(bool os, ) = payable(owner()).call{value: address(this).balance}('');
require(os);
}```
so it should be possible...
I am a newbie in the blockchain technology and I have question.
I just deployed an Ethereum smart contract to the Rinkeby testnet network and minted a few NFTs. When checking my contract address on rinkeby.etherscan.io I can see the smart contract's balance.
The question is, how can I transfer these ethereum in the smart contract balance to my wallet. Since I am the owner I should receive these ETH somehow to my metamask wallet no?
Smart contract includes the following function
// This will transfer the remaining contract balance to the owner.
// Do not remove this otherwise you will not be able to withdraw the funds.
(bool os, ) = payable(owner()).call{value: address(this).balance}('');
require(os);
}```
so it should be possible...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您当前的实施,您需要从
所有者
地址从合同中提取ETH时,从所有者
地址手动调用fort()
函数。您的薄荷功能接受ETH并将其保留在合同地址上。
如果要将资金转移到
所有者
每次执行薄荷时,都需要明确调用每个薄荷功能的传输。例子:Per your current implementation, you need to manually invoke the
withdraw()
function from theowner
address each time you want to withdraw ETH from the contract.Your mint functions accept ETH and keep it on the contract address.
If you want to transfer the funds to the
owner
each time a mint is performed, you need to explicitly invoke the transfer from each of the mint functions. Example:要能够将资金从合同中提取到您拥有的钱包
中/access/ownable.sol“; 使用
唯一的atherer
修饰符。这只允许部署合同的人撤回资金,没有其他人。这是必须的。希望这会有所帮助。To be able to withdraw the funds from your contract to a wallet you own you must implement a
withdraw
method like so:You will also need to make sure that you import
import "@openzeppelin/contracts/access/Ownable.sol";
to use theonlyOwner
modifier. This allows only the person who deployed the contract to withdraw the funds and nobody else. This is a must. Hope this helps.