コード例 #1
0
ファイル: GnosisSafeTests.cs プロジェクト: huyen-pk/Nethereum
        //[Fact] //replace private keys to avoid issues

        public async void ShouldTransferTokensUsingARelayer()
        {
            //gnosis safe owner private key (only one in this scenario)
            var walletOwnerPrivateKey = "0xcf0d584dba3902252f3762d5161c4996f4b364e6e79a75c96b2e2c3e";

            //relayer or account that is going to send the transaction (no relation to the gnosis safe)
            //pays the transaction
            var accountRelayerReceiverPrivateKey = "0xa261c1c7f775c3423be58cdb8c24c6e29f898af56e8699107aa2";
            var chainId = Chain.Rinkeby;

            var gnosisSafeAddress = "0xa9C09412C1d93DAc6eE9254A51E97454588D3B88";
            //contract address of the dai
            var daiAddress = "0x6a9865ade2b6207daac49f8bcba9705deb0b0e6d";

            var accountRelayerReceiver = new Account(accountRelayerReceiverPrivateKey, chainId);

            var web3Url = _ethereumClientIntegrationFixture.GetInfuraUrl(InfuraNetwork.Rinkeby);
            var web3    = new Web3.Web3(accountRelayerReceiver, web3Url);

            var service = new GnosisSafeService(web3, gnosisSafeAddress);

            var transfer = new TransferFunction()
            {
                To    = accountRelayerReceiver.Address,
                Value = Web3.Web3.Convert.ToWei(1)
            };

            var gasPrice = await web3.Eth.GasPrice.SendRequestAsync();

            var execTransactionFunction = await service.BuildTransactionAsync(
                new EncodeTransactionDataFunction()
            {
                To = daiAddress
            }, transfer, (int)chainId, false,
                walletOwnerPrivateKey);

            //legacy
            execTransactionFunction.GasPrice = gasPrice;
            var tokenService  = new StandardTokenEIP20.StandardTokenService(web3, daiAddress);
            var balanceBefore = await tokenService.BalanceOfQueryAsync(accountRelayerReceiver.Address);



            var receipt = await service.ExecTransactionRequestAndWaitForReceiptAsync(execTransactionFunction);

            Assert.False(receipt.HasErrors());
            var balanceAfter = await tokenService.BalanceOfQueryAsync(accountRelayerReceiver.Address);

            Assert.Equal(Web3.Web3.Convert.FromWei(balanceBefore) + 1, Web3.Web3.Convert.FromWei(balanceAfter));
        }
コード例 #2
0
ファイル: GnosisSafeTests.cs プロジェクト: huyen-pk/Nethereum
        //[Fact] //replace private keys to avoid issues
        public async void ShouldDoMultiTransferTokensUsingARelayer()
        {
            var walletOwnerPrivateKey            = "0xcf0d584dba3902252f3762d5161c4996f4b364e6e79a75c96b2e2c3e3";
            var accountRelayerReceiverPrivateKey = "0xa261c1c7f775c3423be58cdb8c24c6e29f898af56e8699107aa219a0";
            var chainId           = Chain.Rinkeby;
            var gnosisSafeAddress = "0xa9C09412C1d93DAc6eE9254A51E97454588D3B88";
            var daiAddress        = "0x6a9865ade2b6207daac49f8bcba9705deb0b0e6d";
            var multiSendAddress  = "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D";

            var accountRelayerReceiver = new Account(accountRelayerReceiverPrivateKey, chainId);

            var web3Url = _ethereumClientIntegrationFixture.GetInfuraUrl(InfuraNetwork.Rinkeby);
            var web3    = new Web3.Web3(accountRelayerReceiver, web3Url);
            var service = new GnosisSafeService(web3, gnosisSafeAddress);

            var transfer = new TransferFunction()
            {
                To    = accountRelayerReceiver.Address,
                Value = Web3.Web3.Convert.ToWei(1)
            };


            var gasPrice = await web3.Eth.GasPrice.SendRequestAsync();

            var execTransactionFunction = await service.BuildMultiSendTransactionAsync(
                new EncodeTransactionDataFunction()
            {
                To = multiSendAddress
            }, (int)chainId, walletOwnerPrivateKey, false,
                new MultiSendFunctionInput <TransferFunction>(transfer, daiAddress),
                new MultiSendFunctionInput <TransferFunction>(transfer, daiAddress)
                );

            //legacy
            execTransactionFunction.GasPrice = gasPrice;
            var tokenService  = new StandardTokenEIP20.StandardTokenService(web3, daiAddress);
            var balanceBefore = await tokenService.BalanceOfQueryAsync(accountRelayerReceiver.Address);



            var receipt = await service.ExecTransactionRequestAndWaitForReceiptAsync(execTransactionFunction);

            Assert.False(receipt.HasErrors());
            var balanceAfter = await tokenService.BalanceOfQueryAsync(accountRelayerReceiver.Address);

            Assert.Equal(Web3.Web3.Convert.FromWei(balanceBefore) + 2, Web3.Web3.Convert.FromWei(balanceAfter));
        }