# 账户(Accounts)

# 引入模组

from ethereum_scan.features.obj import Key, Accounts

# 获取单个地址的ETH余额

# 方法说明

该方法获取单个指定地址中的ETH余额

# 参数说明

参数 描述 参数类型 是否必须 默认值
address 需要检索的ETH地址 string
tag 检索的类型,分别为: 最早(earliest),待定(pending),最新(latest) string latest

# 示例代码

from ethereum_scan.features.obj import Key, Accounts
# 实例化密钥类
key = Key(api_key="你申请的API-KEY")
# 实例化账户类
accounts = Accounts(key)
# 获取ETH余额
eth_balance = accounts.get_ether_balance_for_a_single_address(address="需要检索的ETH地址")
# 打印ETH余额
print(eth_balance)

# 运行结果

1.000000

# 获取多个地址的ETH余额

# 方法说明

WARNING

一次调用最多20个ETH地址, 否则会强行切片成20个

该方法获取多个指定地址中的ETH余额

# 参数说明

参数 描述 参数类型 是否必须 默认值
address 需要检索的ETH地址列表 list
tag 检索的类型,分别为: 最早(earliest),待定(pending),最新(latest) string latest

# 示例代码

from ethereum_scan.features.obj import Key, Accounts
# 实例化密钥类
key = Key(api_key="你申请的API-KEY")
# 实例化账户类
accounts = Accounts(key)
# 设置地址列表
address_list = ["ETH地址1", "ETH地址2"]
# 获取ETH余额
eth_balance_list = accounts.get_the_ether_balance_of_multiple_addresses(address_list=address_list)
# 打印ETH余额
for i in eth_balance_list:
    print(i)

# 运行结果

{'account': 'ETH地址1', 'balance': 1.000000}
{'account': 'ETH地址2', 'balance': 1.000000}

# 按地址获取“正常”交易列表

# 方法说明

WARNING

最多返回10000条数据

该方法用于获取指定ETH地址的“正常”交易列表

# 参数说明

参数 描述 参数类型 是否必须 默认值
address 需要检索的ETH地址 string
start_block 起始块 int 0
end_block 结束块 int 99999999
page 页数 int 1
offset 数量 int 100
sort 排序方式分别为: 升序排序(asc), 降序排序(desc) string desc

# 示例代码

from ethereum_scan.features.obj import Key, Accounts
# 实例化密钥类
key = Key(api_key="你申请的API-KEY")
# 实例化账户类
accounts = Accounts(key)
# 获取交易列表
transaction_list = accounts.get_a_list_of_normal_transactions_by_address(address="ETH地址")
# 遍历交易列表
for i in transaction_list:
    print(i)

# 运行结果

{
    "blockNumber":"0",
    "timeStamp":"1438269973",
    "hash":"GENESIS_ddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
    "nonce":"",
    "blockHash":"",
    "transactionIndex":"0",
    "from":"GENESIS",
    "to":"0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
    "value":"10000000000000000000000",
    "gas":"0",
    "gasPrice":"0",
    "isError":"0",
    "txreceipt_status":"",
    "input":"",
    "contractAddress":"",
    "cumulativeGasUsed":"0",
    "gasUsed":"0",
    "confirmations":"12698061"
},
{
    "blockNumber":"47884",
    "timeStamp":"1438947953",
    "hash":"0xad1c27dd8d0329dbc400021d7477b34ac41e84365bd54b45a4019a15deb10c0d",
    "nonce":"0",
    "blockHash":"0xf2988b9870e092f2898662ccdbc06e0e320a08139e9c6be98d0ce372f8611f22",
    "transactionIndex":"0",
    "from":"0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
    "to":"0x2910543af39aba0cd09dbb2d50200b3e800a63d2",
    "value":"5000000000000000000",
    "gas":"23000",
    "gasPrice":"400000000000",
    "isError":"0",
    "txreceipt_status":"",
    "input":"0x454e34354139455138",
    "contractAddress":"",
    "cumulativeGasUsed":"21612",
    "gasUsed":"21612",
    "confirmations":"12650177"
}

# 按地址获取“内部”交易列表

# 方法说明

WARNING

最多返回10000条数据

该方法用于获取指定ETH地址的“内部”交易列表

# 参数说明

参数 描述 参数类型 是否必须 默认值
address 需要检索的ETH地址 string
start_block 起始块 int 0
end_block 结束块 int 99999999
page 页数 int 1
offset 数量 int 100
sort 排序方式分别为: 升序排序(asc), 降序排序(desc) string desc

# 示例代码

from ethereum_scan.features.obj import Key, Accounts
# 实例化密钥类
key = Key(api_key="你申请的API-KEY")
# 实例化账户类
accounts = Accounts(key)
# 获取交易列表
transaction_list = accounts.get_a_list_of_internal_transactions_by_address(address="ETH地址")
# 遍历交易列表
for i in transaction_list:
    print(i)

# 运行结果


{
    "blockNumber":"2535368",
    "timeStamp":"1477837690",
    "hash":"0x8a1a9989bda84f80143181a68bc137ecefa64d0d4ebde45dd94fc0cf49e70cb6",
    "from":"0x20d42f2e99a421147acf198d775395cac2e8b03d",
    "to":"",
    "value":"0",
    "contractAddress":"0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3",
    "input":"",
    "type":"create",
    "gas":"254791",
    "gasUsed":"46750",
    "traceId":"0",
    "isError":"0",
    "errCode":""
},
{
    "blockNumber":"2535479",
    "timeStamp":"1477839134",
    "hash":"0x1a50f1dc0bc912745f7d09b988669f71d199719e2fb7592c2074ede9578032d0",
    "from":"0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3",
    "to":"0x20d42f2e99a421147acf198d775395cac2e8b03d",
    "value":"100000000000000000",
    "contractAddress":"",
    "input":"",
    "type":"call",
    "gas":"235231",
    "gasUsed":"0",
    "traceId":"0",
    "isError":"0",
    "errCode":""
}

# 通过事务哈希获取“内部事务”

# 方法说明

WARNING

最多返回10000条数据

该方法通过指定的交易Hash值获取该Hash的内部交易事务

# 参数说明

参数 描述 参数类型 是否必须 默认值
txhash 交易的Hash string

# 示例代码

from ethereum_scan.features.obj import Key, Accounts
# 实例化密钥类
key = Key(api_key="你申请的API-KEY")
# 实例化账户类
accounts = Accounts(key)
# 获取交易列表
transaction_list = accounts.get_internal_transactions_by_transaction_hash(txhash="需要检索的交易Hash")
# 遍历交易列表
for i in transaction_list:
    print(i)

# 运行结果

{
    "blockNumber":"1743059",
    "timeStamp":"1466489498",
    "from":"0x2cac6e4b11d6b58f6d3c1c9d5fe8faa89f60e5a2",
    "to":"0x66a1c3eaf0f1ffc28d209c0763ed0ca614f3b002",
    "value":"7106740000000000",
    "contractAddress":"",
    "input":"",
    "type":"call",
    "gas":"2300",
    "gasUsed":"0",
    "isError":"0",
    "errCode":""
}

# 按区块范围获取“内部交易”

# 方法说明

WARNING

最多返回10000条数据

该方法通过指定的区块范围, 获取该范围下所有的交易

# 参数说明

参数 描述 参数类型 是否必须 默认值
start_block 起始块 int 0
end_block 结束块 int 99999999
page 页数 int 1
offset 数量 int 100
sort 排序方式分别为: 升序排序(asc), 降序排序(desc) string desc

# 示例代码

from ethereum_scan.features.obj import Key, Accounts
# 实例化密钥类
key = Key(api_key="你申请的API-KEY")
# 实例化账户类
accounts = Accounts(key)
# 获取交易列表
transaction_list = accounts.get_internal_transactions_by_block_range(start_block=1900000, end_block=2000000)
# 遍历交易列表
for i in transaction_list:
    print(i)

# 运行结果

{
    "blockNumber":"50107",
    "timeStamp":"1438984016",
    "hash":"0x3f97c969ddf71f515ce5373b1f8e76e9fd7016611d8ce455881009414301789e",
    "from":"0x109c4f2ccc82c4d77bde15f306707320294aea3f",
    "to":"0x881b0a4e9c55d08e31d8d3c022144d75a454211c",
    "value":"1000000000000000000",
    "contractAddress":"",
    "input":"",
    "type":"call",
    "gas":"2300",
    "gasUsed":"0",
    "traceId":"0",
    "isError":"1",
    "errCode":""
},
{
    "blockNumber":"50111",
    "timeStamp":"1438984075",
    "hash":"0x893c428fed019404f704cf4d9be977ed9ca01050ed93dccdd6c169422155586f",
    "from":"0x109c4f2ccc82c4d77bde15f306707320294aea3f",
    "to":"0x881b0a4e9c55d08e31d8d3c022144d75a454211c",
    "value":"1000000000000000000",
    "contractAddress":"",
    "input":"",
    "type":"call",
    "gas":"2300",
    "gasUsed":"0",
    "traceId":"0",
    "isError":"0",
    "errCode":""
}

# 按地址获取“ERC20 - 代币转移事件”列表

# 方法说明

该方法通过指定的ETH地址和智能合约地址,获取该代币的交易列表

# 参数说明

参数 描述 参数类型 是否必须 默认值
address 需要检索的ETH地址 string
contract_address 需要检索的智能合约地址 string
start_block 起始块 int 0
end_block 结束块 int 99999999
page 页数 int 1
offset 数量 int 100
sort 排序方式分别为: 升序排序(asc), 降序排序(desc) string desc

# 示例代码

from ethereum_scan.features.obj import Key, Accounts
# 实例化密钥类
key = Key(api_key="你申请的API-KEY")
# 实例化账户类
accounts = Accounts(key)
# 获取交易列表
transaction_list = accounts.get_a_list_of_erc20_token_transfer_events_by_address(address="ETH地址", contract_address="智能合约地址")
# 编列交易列表
for i in transaction_list:
    print(i)

# 运行结果

{
    "blockNumber":"4730207",
    "timeStamp":"1513240363",
    "hash":"0xe8c208398bd5ae8e4c237658580db56a2a94dfa0ca382c99b776fa6e7d31d5b4",
    "nonce":"406",
    "blockHash":"0x022c5e6a3d2487a8ccf8946a2ffb74938bf8e5c8a3f6d91b41c56378a96b5c37",
    "from":"0x642ae78fafbb8032da552d619ad43f1d81e4dd7c",
    "contractAddress":"0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2",
    "to":"0x4e83362442b8d1bec281594cea3050c8eb01311c",
    "value":"5901522149285533025181",
    "tokenName":"Maker",
    "tokenSymbol":"MKR",
    "tokenDecimal":"18",
    "transactionIndex":"81",
    "gas":"940000",
    "gasPrice":"32010000000",
    "gasUsed":"77759",
    "cumulativeGasUsed":"2523379",
    "input":"deprecated",
    "confirmations":"7968350"
},
{
    "blockNumber":"4764973",
    "timeStamp":"1513764636",
    "hash":"0x9c82e89b7f6a4405d11c361adb6d808d27bcd9db3b04b3fb3bc05d182bbc5d6f",
    "nonce":"428",
    "blockHash":"0x87a4d04a6d8fce7a149e9dc528b88dc0c781a87456910c42984bdc15930a2cac",
    "from":"0x4e83362442b8d1bec281594cea3050c8eb01311c",
    "contractAddress":"0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2",
    "to":"0x69076e44a9c70a67d5b79d95795aba299083c275",
    "value":"132520488141080",
    "tokenName":"Maker",
    "tokenSymbol":"MKR",
    "tokenDecimal":"18",
    "transactionIndex":"167",
    "gas":"940000",
    "gasPrice":"35828000000",
    "gasUsed":"127593",
    "cumulativeGasUsed":"6315818",
    "input":"deprecated",
    "confirmations":"7933584"
}

# 按地址获取“ERC721 - 代币转移事件”列表

# 方法说明

该方法通过指定的ETH地址和智能合约地址,获取该代币的交易列表

# 参数说明

参数 描述 参数类型 是否必须 默认值
address 需要检索的ETH地址 string
contract_address 需要检索的智能合约地址 string
start_block 起始块 int 0
end_block 结束块 int 99999999
page 页数 int 1
offset 数量 int 100
sort 排序方式分别为: 升序排序(asc), 降序排序(desc) string desc

# 示例代码

from ethereum_scan.features.obj import Key, Accounts
# 实例化密钥类
key = Key(api_key="你申请的API-KEY")
# 实例化账户类
accounts = Accounts(key)
# 获取交易列表
transaction_list = accounts.get_a_list_of_erc721_token_transfer_events_by_address(address="ETH地址", contract_address="智能合约地址")
# 编列交易列表
for i in transaction_list:
    print(i)

# 运行结果

{
    "blockNumber":"4708120",
    "timeStamp":"1512907118",
    "hash":"0x031e6968a8de362e4328d60dcc7f72f0d6fc84284c452f63176632177146de66",
    "nonce":"0",
    "blockHash":"0x4be19c278bfaead5cb0bc9476fa632e2447f6e6259e0303af210302d22779a24",
    "from":"0xb1690c08e213a35ed9bab7b318de14420fb57d8c",
    "contractAddress":"0x06012c8cf97bead5deae237070f9587f8e7a266d",
    "to":"0x6975be450864c02b4613023c2152ee0743572325",
    "tokenID":"202106",
    "tokenName":"CryptoKitties",
    "tokenSymbol":"CK",
    "tokenDecimal":"0",
    "transactionIndex":"81",
    "gas":"158820",
    "gasPrice":"40000000000",
    "gasUsed":"60508",
    "cumulativeGasUsed":"4880352",
    "input":"deprecated",
    "confirmations":"7990490"
},
{
    "blockNumber":"4708161",
    "timeStamp":"1512907756",
    "hash":"0x9626e7064b68b5463cf677e10815a0b394645a0bfa245f26a2de6074324e83ff",
    "nonce":"1",
    "blockHash":"0xe1c6cbc39a723496f4cbc3e70241012854f2e88b4d2d5f339d8f0a4a1cc406d8",
    "from":"0xb1690c08e213a35ed9bab7b318de14420fb57d8c",
    "contractAddress":"0x06012c8cf97bead5deae237070f9587f8e7a266d",
    "to":"0x6975be450864c02b4613023c2152ee0743572325",
    "tokenID":"147739",
    "tokenName":"CryptoKitties",
    "tokenSymbol":"CK",
    "tokenDecimal":"0",
    "transactionIndex":"41",
    "gas":"135963",
    "gasPrice":"40000000000",
    "gasUsed":"45508",
    "cumulativeGasUsed":"3359342",
    "input":"deprecated",
    "confirmations":"7990449"
}

# 按地址获取“ERC1155 - 代币转移事件”列表

# 方法说明

该方法通过指定的ETH地址和智能合约地址,获取该代币的交易列表

# 参数说明

参数 描述 参数类型 是否必须 默认值
address 需要检索的ETH地址 string
contract_address 需要检索的智能合约地址 string
start_block 起始块 int 0
end_block 结束块 int 99999999
page 页数 int 1
offset 数量 int 100
sort 排序方式分别为: 升序排序(asc), 降序排序(desc) string desc

# 示例代码

from ethereum_scan.features.obj import Key, Accounts
# 实例化密钥类
key = Key(api_key="你申请的API-KEY")
# 实例化账户类
accounts = Accounts(key)
# 获取交易列表
transaction_list = accounts.get_a_list_of_erc1155_token_transfer_events_by_address(address="ETH地址", contract_address="智能合约地址")
# 遍历交易列表
for i in transaction_list:
    print(i)

# 运行结果

{
    "blockNumber":"13472395",
    "timeStamp":"1634973285",
    "hash":"0x643b15f3ffaad5d38e33e5872b4ebaa7a643eda8b50ffd5331f682934ee65d4d",
    "nonce":"41",
    "blockHash":"0xa5da536dfbe8125eb146114e2ee0d0bdef2b20483aacbf30fed6b60f092059e6",
    "transactionIndex":"100",
    "gas":"140000",
    "gasPrice":"52898577246",
    "gasUsed":"105030",
    "cumulativeGasUsed":"11739203",
    "input":"deprecated",
    "contractAddress":"0x76be3b62873462d2142405439777e971754e8e77",
    "from":"0x1e63326a84d2fa207bdfa856da9278a93deba418",
    "to":"0x83f564d180b58ad9a02a449105568189ee7de8cb",
    "tokenID":"10371",
    "tokenValue":"1",
    "tokenName":"parallel",
    "tokenSymbol":"LL",
    "confirmations":"1447769"
},
{
    "blockNumber":"14049909",
    "timeStamp":"1642781541",
    "hash":"0x58353aab15a4b5a77333b87619edaa749c7f3cf8bb2263a1c0865d73bf1264bd",
    "nonce":"4",
    "blockHash":"0x1e88a63a4cb4086a747644b8ab7ff3434540930f3029eacb8add08b15974fdc9",
    "transactionIndex":"114",
    "gas":"253032",
    "gasPrice":"225052869211",
    "gasUsed":"184899",
    "cumulativeGasUsed":"6855790",
    "input":"deprecated",
    "contractAddress":"0x76be3b62873462d2142405439777e971754e8e77",
    "from":"0x83f564d180b58ad9a02a449105568189ee7de8cb",
    "to":"0x80833dc92d326a81d0cb74982a8e6f1a3887f837",
    "tokenID":"10371",
    "tokenValue":"1",
    "tokenName":"parallel",
    "tokenSymbol":"LL",
    "confirmations":"870255"
},
{
    "blockNumber":"14067255",
    "timeStamp":"1643012777",
    "hash":"0x3222b5f71e577c2551e17701eaf39b308b976bbe6bf6ce3f8c20549527b9d6ae",
    "nonce":"7",
    "blockHash":"0x236cfed8b42fa6cb8956f6e7b889797047d9af0883066b1f3be8284beda16e17",
    "transactionIndex":"172",
    "gas":"56873",
    "gasPrice":"69434775835",
    "gasUsed":"52073",
    "cumulativeGasUsed":"17181952",
    "input":"deprecated",
    "contractAddress":"0x76be3b62873462d2142405439777e971754e8e77",
    "from":"0x9d48305f859a0006b57da25c80af62ecb8e5c6a2",
    "to":"0x83f564d180b58ad9a02a449105568189ee7de8cb",
    "tokenID":"10372",
    "tokenValue":"1",
    "tokenName":"parallel",
    "tokenSymbol":"LL",
    "confirmations":"852909"
}

# 获取按地址挖掘的区块列表

# 方法说明

该方法会返回指定ETH的挖掘的区块列表

# 参数说明

参数 描述 参数类型 是否必须 默认值
address 需要检索的ETH地址 string
blocktype 块类型(blocks(标准块), uncles(叔块)) string
page 页数 int 1
offset 数量 int 100

# 示例代码

from ethereum_scan.features.obj import Key, Accounts
# 实例化密钥类
key = Key(api_key="你申请的API-KEY")
# 实例化账户类
accounts = Accounts(key)
# 获取块列表
blocks_list = accounts.get_list_of_blocks_mined_by_address(address="0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b")
# 遍历块列表
for i in blocks_list:
    print(i)

# 运行结果

{
    "blockNumber":"3462296",
    "timeStamp":"1491118514",
    "blockReward":"5194770940000000000"
},
{
    "blockNumber":"2691400",
    "timeStamp":"1480072029",
    "blockReward":"5086562212310617100"
},
{
    "blockNumber":"2687700",
    "timeStamp":"1480018852",
    "blockReward":"5003251945421042780"
}

# 通过 BlockNo 获取单个地址的历史以太币余额 -- PRO

WARNING

此接口被限制为2次/S

# 方法说明

该方法通过指定的区块号,获取单个地址的历史ETH余额

# 参数说明

参数 描述 参数类型 是否必须 默认值
address 需要检索的ETH地址 string
blockno 块类型(blocks(标准块), uncles(叔块)) string

# 示例代码

from ethereum_scan.features.obj import Key, Accounts
# 实例化密钥类
key = Key(api_key="你申请的API-KEY")
# 实例化账户类
accounts = Accounts(key)
# 获取区块号获取指定地址的ETH余额, -- 该方法需要PRO版本才能使用
eth_balance = accounts.get_ether_balance_for_a_single_address(address="需要检索的ETH地址", blockno="区块号")
# 打印ETH余额
print(eth_balance)

# 运行结果

1.000000