Пример #1
0
        public async void ShouldDeployCustomAndQueryInteractWithGenericService()
        {
            var web3 = _ethereumClientIntegrationFixture.GetWeb3();

            web3.Eth.TransactionManager.UseLegacyAsDefault = true;


            var ercERC1155Deployment = new MyERC1155Deployment();
            //Deploy the 1155 contract (shop)
            var deploymentReceipt = await web3.Eth.GetContractDeploymentHandler <MyERC1155Deployment>().SendRequestAndWaitForReceiptAsync(ercERC1155Deployment);

            //creating a new service with the new contract address
            var erc1155Service             = web3.Eth.GetERC1155Service(deploymentReceipt.ContractAddress);
            var id                         = 123456789;
            var url                        = "ipfs://bafkreiblz4ltiepapdhqhjiurmfpov7extmxwcntqskvx2zqisoftlmk7a";
            var amount                     = 100;
            var addressToRegisterOwnership = "0xe612205919814b1995D861Bdf6C2fE2f20cDBd68";

            //Adding the product information
            var tokenUriReceipt = await erc1155Service.SetTokenUriRequestAndWaitForReceiptAsync(id,
                                                                                                url);

            var mintReceipt = await erc1155Service.MintRequestAndWaitForReceiptAsync(web3.TransactionManager.Account.Address, id, amount, new byte[] { });


            // the balance should be
            var balance = await erc1155Service.BalanceOfQueryAsync(web3.TransactionManager.Account.Address, id);

            Assert.Equal(amount, balance);

            var addressOfToken = await erc1155Service.UriQueryAsync(id);

            Assert.Equal(url, addressOfToken);

            //lets sell 2
            var transfer = await erc1155Service.SafeTransferFromRequestAndWaitForReceiptAsync(web3.TransactionManager.Account.Address, addressToRegisterOwnership, id, 2, new byte[] { });

            Assert.False(transfer.HasErrors());

            var balance2 = await erc1155Service.BalanceOfQueryAsync(addressToRegisterOwnership, id);

            Assert.Equal(2, balance2);
        }
        public async void ShouldDeployAndMintoken()
        {
            //Using rinkeby to demo opensea, if we dont want to use the configured client
            //please input your infura id in appsettings.test.json
            var web3 = _ethereumClientIntegrationFixture.GetInfuraWeb3(InfuraNetwork.Rinkeby);

            //var web3 = _ethereumClientIntegrationFixture.GetWeb3(); //if you want to use your local node (ie geth, uncomment this, see appsettings.test.json for further info)
            //example of configuration as legacy (not eip1559) to work on L2s
            web3.Eth.TransactionManager.UseLegacyAsDefault = true;


            var ercERC1155Deployment = new MyERC1155Deployment();
            //Deploy the 1155 contract (shop)
            var deploymentReceipt = await MyERC1155Service.DeployContractAndWaitForReceiptAsync(web3, ercERC1155Deployment);

            //creating a new service with the new contract address
            var erc1155Service = new MyERC1155Service(web3, deploymentReceipt.ContractAddress);

            //uploading to ipfs our documents
            var nftIpfsService = new NFTIpfsService("https://ipfs.infura.io:5001");
            var imageIpfs      = await nftIpfsService.AddFileToIpfsAsync("ShopImages/hard-drive-by-vincent-botta-from-unsplash.jpg");


            //adding all our document ipfs links to the metadata and the description
            var metadataNFT = new ProductNFTMetadata()
            {
                ProductId   = 12131,
                Name        = "4TB Black Performance Desktop Hard Drive",
                Image       = "ipfs://" + imageIpfs.Hash, //The image is what is displayed in market places like opean sea
                Description = @"Capacity: 4TB
                                Interface: SATA 6Gb / s
                                Form Factor: 3.5 Inch
                                Easy Backup and Upgrade
                                5 Year Warranty (Photo by: Vincent Botta https://unsplash.com/@0asa)",
                ExternalUrl = "https://github.com/Nethereum/ERC721ContractLibrary.Template",
                Decimals    = 0
            };
            var stockHardDrive = 100;
            //Adding the metadata to ipfs
            var metadataIpfs =
                await nftIpfsService.AddNftsMetadataToIpfsAsync(metadataNFT, metadataNFT.ProductId + ".json");

            var addressToRegisterOwnership = "0xe612205919814b1995D861Bdf6C2fE2f20cDBd68";

            //Adding the product information
            var tokenUriReceipt = await erc1155Service.SetTokenUriRequestAndWaitForReceiptAsync(metadataNFT.ProductId,
                                                                                                "ipfs://" + metadataIpfs.Hash);

            var mintReceipt = await erc1155Service.MintRequestAndWaitForReceiptAsync(addressToRegisterOwnership, metadataNFT.ProductId, stockHardDrive, new byte[] {});


            // the balance should be
            var balance = await erc1155Service.BalanceOfQueryAsync(addressToRegisterOwnership, (BigInteger)metadataNFT.ProductId);

            Assert.Equal(stockHardDrive, balance);

            var addressOfToken = await erc1155Service.UriQueryAsync(metadataNFT.ProductId);

            Assert.Equal("ipfs://" + metadataIpfs.Hash, addressOfToken);

            //Url format  https://testnets.opensea.io/assets/[nftAddress]/[id]
            //opening opensea testnet to visualise the nft
            var ps = new ProcessStartInfo("https://testnets.opensea.io/assets/" + deploymentReceipt.ContractAddress + "/" + metadataNFT.ProductId)
            {
                UseShellExecute = true,
                Verb            = "open"
            };

            Process.Start(ps);

            //lets sell 2 hard drives
            var transfer = await erc1155Service.SafeTransferFromRequestAndWaitForReceiptAsync(addressToRegisterOwnership, addressToRegisterOwnership, (BigInteger)metadataNFT.ProductId, 2, new byte[] {});

            Assert.False(transfer.HasErrors());
        }
        public static async Task <MyERC1155Service> DeployContractAndGetServiceAsync(Nethereum.Web3.Web3 web3, MyERC1155Deployment myERC1155Deployment, CancellationTokenSource cancellationTokenSource = null)
        {
            var receipt = await DeployContractAndWaitForReceiptAsync(web3, myERC1155Deployment, cancellationTokenSource);

            return(new MyERC1155Service(web3, receipt.ContractAddress));
        }
 public static Task <string> DeployContractAsync(Nethereum.Web3.Web3 web3, MyERC1155Deployment myERC1155Deployment)
 {
     return(web3.Eth.GetContractDeploymentHandler <MyERC1155Deployment>().SendRequestAsync(myERC1155Deployment));
 }
 public static Task <TransactionReceipt> DeployContractAndWaitForReceiptAsync(Nethereum.Web3.Web3 web3, MyERC1155Deployment myERC1155Deployment, CancellationTokenSource cancellationTokenSource = null)
 {
     return(web3.Eth.GetContractDeploymentHandler <MyERC1155Deployment>().SendRequestAndWaitForReceiptAsync(myERC1155Deployment, cancellationTokenSource));
 }