Solidity

如何使用 Web3.js 將乙太幣存入智能合約

  • May 19, 2019

因此,我正在創建一個與部署在 Ropsten 測試網上的智能合約互動的 Web 應用程序。

我可以使用提現功能將乙太幣從合約中提現到我的 Metamask 賬戶。

但是,我正在努力尋找將乙太幣存入智能合約的正確方法,即我需要使用什麼語法/功能。我的合約肯定是 Payable(),當我通過 Etherscan 查看並與之互動時,我可以存入乙太幣。

任何幫助將不勝感激,因為我承受著很大的壓力。謝謝!

這是我如何提取乙太幣的方法……現在我需要一個存款功能

abi = JSON.parse('[{"constant":false,"inputs":[{"name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getMyBalance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"deposit","outputs":[],"payable":true,"stateMutability":"payable","type":"function"}]');
var bankContract = web3.eth.contract(abi);
contractInstance = bankContract.at('TheContractAddressHere');

function withdraw() {
 contractInstance.withdraw(300000000000000000, { from: web3.eth.accounts[0]}, function(err, result){ revert(); } );
}
function depositFunction() {    
   contractInstance.deposit({ from: web3.eth.accounts[0], value: <amount-in-Wei>}, function(err, result){ .... } );
}

引用自:https://ethereum.stackexchange.com/questions/70858