Skip to content

Commit 22f390d

Browse files
committed
Utils.IsDeployed
1 parent 9989a3d commit 22f390d

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Thirdweb.Tests/Thirdweb.Utils/Thirdweb.Utils.Tests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,4 +584,33 @@ public async Task GetAddressFromENS_ReturnsAddress_WhenENSNameIsValid()
584584
result = await Utils.GetAddressFromENS(this.Client, validENSName);
585585
Assert.Equal(expectedAddress.ToChecksumAddress(), result);
586586
}
587+
588+
/*
589+
public static async Task<bool> IsDeployed(ThirdwebClient client, BigInteger chainId, string address)
590+
{
591+
var rpc = ThirdwebRPC.GetRpcInstance(client, chainId);
592+
var code = await rpc.SendRequestAsync<string>("eth_getCode", address, "latest");
593+
return code != "0x";
594+
}
595+
*/
596+
597+
[Fact(Timeout = 120000)]
598+
public async Task IsDeployed_ReturnsTrue_WhenContractIsDeployed()
599+
{
600+
var chainId = new BigInteger(1);
601+
var address = "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D";
602+
var isDeployed = await Utils.IsDeployed(this.Client, chainId, address);
603+
604+
Assert.True(isDeployed);
605+
}
606+
607+
[Fact(Timeout = 120000)]
608+
public async Task IsDeployed_ReturnsFalse_WhenContractIsNotDeployed()
609+
{
610+
var chainId = new BigInteger(1);
611+
var address = await Utils.GetAddressFromENS(this.Client, "vitalik.eth");
612+
var isDeployed = await Utils.IsDeployed(this.Client, chainId, address);
613+
614+
Assert.False(isDeployed);
615+
}
587616
}

Thirdweb/Thirdweb.Utils/Utils.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,4 +835,11 @@ private static string NameHash(string name)
835835
}
836836
return node.EnsureHexPrefix();
837837
}
838+
839+
public static async Task<bool> IsDeployed(ThirdwebClient client, BigInteger chainId, string address)
840+
{
841+
var rpc = ThirdwebRPC.GetRpcInstance(client, chainId);
842+
var code = await rpc.SendRequestAsync<string>("eth_getCode", address, "latest");
843+
return code != "0x";
844+
}
838845
}

0 commit comments

Comments
 (0)