modified Lockdrop.sol with the changes shown in this commit https://github.com/DataHighway-DHX/mining/commit/18c59a2c646633d1687fcba7adc637e7931f8572
so that the Lock contract that it generates is deployed first, and then we deposit or withdraw from it only after providing approval from the ERC20 token by running its approve
function (like what Test.sol did)
instead of constructing the contract and performing a deposit before it was possible to grant it permission.
so i deployed Lockdrop.sol to 0x5d030d3f45362f6ccc1f3c29c8cdeb617602d814
i deployed MXCToken (that imports StandardToken) on Rinkeby here: 0x6d8fc9e069f8fbab67a0a93d9cb19d3d16e21ccc
(the same code that MXC used to deploy it to mainnet)
then loaded MXCToken using AtAddress
0x6d8fc9e069f8fbab67a0a93d9cb19d3d16e21ccc
Ran the "lock" function in Lockdrop.sol with arguments: "0x1f7ace08af5c49a5d69fbb98fb9339a729b27161","3","100","0x46765939697a514462737a7a46556b437a65643435547039785062754b4e516e4d563150676b385959444b43573476","0x6d8fc9e069f8fbab67a0a93d9cb19d3d16e21ccc",false
Then I ran the "lockWalletStructs" function in Lockdrop.sol with arguments "0x1f7ace08af5c49a5d69fbb98fb9339a729b27161","0x6d8fc9e069f8fbab67a0a93d9cb19d3d16e21ccc"
which generated an output containing the lockAddr
of the Lock contract address that the Lockdrop contract factory deployed to 0x190E49F7BC58fca0058eCB895119110DccfE0c76
Then I needed to run the approve
function of the ERC20 token that the Lock contract was generated to deposit/withdraw from
So using the MXCToken I clicked approve
using argument "0x190E49F7BC58fca0058eCB895119110DccfE0c76", 100
, and it's mined successfully
Then loaded the Lock contract, using AtAddress
0x190E49F7BC58fca0058eCB895119110DccfE0c76
Then clicked the depositTokens
function button
but it failed with error: https://rinkeby.etherscan.io/tx/0x1b8d3172fcaeee89fd9fae947028c31227cdc66f5d10a5e7a16d1e2240235cc1
so updated Lockdrop's depositTokens function so it only had one line of code
require(token.transferFrom(msg.sender, address(this), lockContractTokenCapacity), "Unable to deposit ERC20 tokens from Lock owner to Lock contract");
then deployed it again to 0x751D132674A6F72cf9E1Fd011Cb95BB31fD63a4F
Ran the "lock" function in Lockdrop.sol with arguments: "0x1f7ace08af5c49a5d69fbb98fb9339a729b27161","3","100","0x46765939697a514462737a7a46556b437a65643435547039785062754b4e516e4d563150676b385959444b43573476","0x6d8fc9e069f8fbab67a0a93d9cb19d3d16e21ccc",false
Then I ran the "lockWalletStructs" function in Lockdrop.sol with arguments "0x1f7ace08af5c49a5d69fbb98fb9339a729b27161","0x6d8fc9e069f8fbab67a0a93d9cb19d3d16e21ccc"
which generated an output containing the lockAddr
of the Lock contract address that the Lockdrop contract factory deployed to 0xb180838D523c7FbCbb2E31962f55877DA6289A34
Then I needed to run the approve
function of the ERC20 token that the Lock contract was generated to deposit/withdraw from
So using the MXCToken I clicked approve
using argument "0xb180838D523c7FbCbb2E31962f55877DA6289A34", 100
, and it's mined successfully
Then loaded the Lock contract, using AtAddress
0xb180838D523c7FbCbb2E31962f55877DA6289A34
Then clicked the depositTokens
function button
but it failed with error: https://rinkeby.etherscan.io/tx/0xb5bef75981bc924b3e2b4df0ff1336e27f71314873c2be162767e050de2372ab
i also tried granting approval to my EOA using argument "0x1f7ace08af5c49a5d69fbb98fb9339a729b27161", 100
, and it's mined successfully
but that failed too with error: https://rinkeby.etherscan.io/tx/0x3c9f5f22f1dc99c044aa2f998675b78bd4927c585b21d1c3223ad164c9995b4c
so I tried using Weenus (instead of MXCToken) with Lockdrop instead:
i deployed a duplicate of Weenus from my account 0x1f... to 0x2d2c5fdfcc44fb2c9cdaebc468d6cb23a809d5cd
I used Lockdrop that I'd deployed to 0x751D132674A6F72cf9E1Fd011Cb95BB31fD63a4F
Ran the "lock" function in Lockdrop.sol with arguments: "0x1f7ace08af5c49a5d69fbb98fb9339a729b27161","3","100","0x46765939697a514462737a7a46556b437a65643435547039785062754b4e516e4d563150676b385959444b43573476","0x2d2c5fdfcc44fb2c9cdaebc468d6cb23a809d5cd",false
https://rinkeby.etherscan.io/tx/0xf26e1b3b09c75954b2bcf1f45b6719f6f725d4582ca6d7b0ad8fc75f01ca1f5b
Then I ran the "lockWalletStructs" function in Lockdrop.sol with arguments "0x1f7ace08af5c49a5d69fbb98fb9339a729b27161","0x2d2c5fdfcc44fb2c9cdaebc468d6cb23a809d5cd"
which generated an output containing the lockAddr
of the Lock contract address that the Lockdrop contract factory deployed to 0x91987C351704Bbc4dBCD3e558B3A1DDd0F3C87A4
then loaded WeenusToken using AtAddress
0x2d2c5fdfcc44fb2c9cdaebc468d6cb23a809d5cd
and clicked approve
using argument "0x91987C351704Bbc4dBCD3e558B3A1DDd0F3C87A4", 100
and clicked balanceOf
using argument of my address "0x1f7ace08af5c49a5d69fbb98fb9339a729b27161" and it showed i had 1000 WEENUS
then loaded the Lock address using AtAddress
0x91987C351704Bbc4dBCD3e558B3A1DDd0F3C87A4
clicked depositTokens
but it failed with error: https://rinkeby.etherscan.io/tx/0x7c1eb47910aa6d4216a119d33398df9fcb9f22cebe2838c3b41de27189b1e9ed
i also tried granting approval to my EOA using argument "0x1f7ace08af5c49a5d69fbb98fb9339a729b27161", 100
clicked depositTokens
but that failed too with same error https://rinkeby.etherscan.io/tx/0x632ccbf8f25d888ddc274cf16300b0137556a71cbc91e6fac0f332b4e3e6dfae
i was only about to run transferFrom
in the Remix UI using the Weenus contract and passing argument "0x1f7ace08af5c49a5d69fbb98fb9339a729b27161", "0x91987C351704Bbc4dBCD3e558B3A1DDd0F3C87A4", 1
2664965800.000000000000000000 total supply 100 000000000000000000 100 MXC (i.e. 100000000000000000000)
removed the ERC20
prefix since wasn't assigning to the variable of the smart contract as highlighted by Bokky
so i deployed Lockdrop.sol to 0x49b8e31962d2ebd5574c9c5761da08b99db39540
https://rinkeby.etherscan.io/tx/0xcf4ec6d86b9f2cab200f6b181e9d44b7b4e9b16c1e1a1a4dca65266e7aa648eb
i deployed MXCToken (that imports StandardToken) on Rinkeby here: 0x6d8fc9e069f8fbab67a0a93d9cb19d3d16e21ccc
(the same code that MXC used to deploy it to mainnet)
then loaded MXCToken using AtAddress
0x6d8fc9e069f8fbab67a0a93d9cb19d3d16e21ccc
Ran the "lock" function in Lockdrop.sol with arguments: "0x1f7ace08af5c49a5d69fbb98fb9339a729b27161","3","100000000000000000000","0x46765939697a514462737a7a46556b437a65643435547039785062754b4e516e4d563150676b385959444b43573476","0x6d8fc9e069f8fbab67a0a93d9cb19d3d16e21ccc",false
Then I ran the "lockWalletStructs" function in Lockdrop.sol with arguments "0x1f7ace08af5c49a5d69fbb98fb9339a729b27161","0x6d8fc9e069f8fbab67a0a93d9cb19d3d16e21ccc"
which generated an output containing the lockAddr
of the Lock contract address that the Lockdrop contract factory deployed to 0xA55d5Ad16742d524Fce5a9B7bC14e9C25c6Ab5Ea
Then I needed to run the approve
function of the ERC20 token that the Lock contract was generated to deposit/withdraw from
So using the MXCToken I clicked approve
using argument "0xA55d5Ad16742d524Fce5a9B7bC14e9C25c6Ab5Ea", 100000000000000000000
, and it's mined successfully
(it is necessary to approve
the amount you want a given spending account, in this case the Lock contract, to be able to spend with transferFrom
,
however it is not necessary to further approve the amount you also want to with with transfer
)
Wait for it to process
Then run the MXCToken's allowance
button to check how much you've allowed the Lock contract to spend with:
"0x1f7ace08af5c49a5d69fbb98fb9339a729b27161", "0xE040d235Cc61D7ccF6EBf1325f233C5458Fc51A6"
It should return 100000000000000000000
Then loaded the Lock contract, using AtAddress
0xA55d5Ad16742d524Fce5a9B7bC14e9C25c6Ab5Ea
Then clicked the depositTokens
function button
and IT WORKED!! https://rinkeby.etherscan.io/tx/0xd5aa3d81d38852ff8690f80a9538717f13a0ef053ac01cc9439086e12def8bbb
BokkyPoohBah thank you!
before withdrawing, keep clicking "lockContractBalance" button until it says the Lock contract has a balance of 100000000000000000000
then using MXCToken run allowance
with arg "0x1f7ace08af5c49a5d69fbb98fb9339a729b27161","0xE040d235Cc61D7ccF6EBf1325f233C5458Fc51A6"
,
and it should return 0 (meaning you can't deposit anymore unless you increase the allowance again)
Then run withdrawTokens
and it should return the 100 MXC tokens back to the original sender
use Ropsten (Rinkeby faucet's don't work)
MXCToken deployed to 0xefa111f81b485f56697c1f56a225f48694ef9e83
Lockdrop deployed to 0xc34e6129a5121570dfe92e4f80f68de075beaf27
Ran the "lock" function in Lockdrop.sol with arguments: "0x1f7ace08af5c49a5d69fbb98fb9339a729b27161","3","100000000000000000000","0x46765939697a514462737a7a46556b437a65643435547039785062754b4e516e4d563150676b385959444b43573476","0xefa111f81b485f56697c1f56a225f48694ef9e83",false
Then I ran the "lockWalletStructs" function in Lockdrop.sol with arguments "0x1f7ace08af5c49a5d69fbb98fb9339a729b27161","0xefa111f81b485f56697c1f56a225f48694ef9e83"
which generated an output containing the lockAddr
of the Lock contract address that the Lockdrop contract factory deployed to 0xcbC003e48881A981bA8f5e565c1D67f7F0e60e1A
run the approve
function of the ERC20 token that the Lock contract was generated to deposit/withdraw from
So using the MXCToken I clicked approve
using argument "0xcbC003e48881A981bA8f5e565c1D67f7F0e60e1A", 100000000000000000000
(it is necessary to approve
the amount you want a given spending account, in this case the Lock contract, to be able to spend with transferFrom
,
however it is not necessary to further approve the amount you also want to with with transfer
)
Wait for it to process
Then run the MXCToken's allowance
button to check how much you've allowed the Lock contract to spend with:
"0x1f7ace08af5c49a5d69fbb98fb9339a729b27161", "0xcbC003e48881A981bA8f5e565c1D67f7F0e60e1A"
It should return 100000000000000000000
Then loaded the Lock contract, using AtAddress
0xcbC003e48881A981bA8f5e565c1D67f7F0e60e1A
Then clicked the depositTokens
function button
before withdrawing, keep clicking "lockContractBalance" button until it says the Lock contract has a balance of 100000000000000000000
then using MXCToken run allowance
with arg "0x1f7ace08af5c49a5d69fbb98fb9339a729b27161","0xcbC003e48881A981bA8f5e565c1D67f7F0e60e1A"
,
and it should return 0 (meaning you can't deposit anymore unless you increase the allowance again)
Then run withdrawTokens
and it should return the 100 MXC tokens back to the original sender
https://ropsten.etherscan.io/tx/0x4c7d998ef7222abea6309dec0990fd4b515abe89a8c97c1753d9e9c9b05d17c1