# python版本的arb空投领取demo

By [junjie9021](https://paragraph.com/@junjie9021-3) · 2023-03-20

---

python版本的arb空投领取demo

    import web3
    import requests
    
    headers = {
        'content-type': 'application/json',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
        }
    
    class Rpc:
        """
        eth rpc方法
        """
        def __init__(self, api='https://arb1.arbitrum.io/rpc', chainid=42161, proxies=None, timeout=30):
            self.api = api
            self.chainid = chainid
            self.proxies = proxies
            self.timeout = timeout
    
        def get_current_block(self):
            """获取最新区块"""
            data = {"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}
            res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
            return res.json()
    
        def get_block_detail(self, number):
            """获取区块hash"""
            if isinstance(number, int):
                number = hex(number)
            data = {"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":[number,True],"id":1}
            res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
            return res.json()
    
        def get_transaction(self, txhash):
            """获取的交易详情"""
            data = {"jsonrpc":"2.0","method":"eth_getTransactionByHash","params":[txhash],"id":1}
            res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
            return res.json()
    
        def get_gas_price(self):
            """获取gasprice"""
            data = {"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":1}
            res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
            return res.json()
    
        def get_gas_limit(self, to, data):
            """call计算gas"""
            data = {"jsonrpc":"2.0","method":"eth_estimateGas","params":[{"to": to, "data": data}],"id":1}
            res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
            return res.json()
    
        def get_transaction_count_by_address(self, address):
            data = {"jsonrpc":"2.0","method":"eth_getTransactionCount","params":[address,'latest'],"id":1}
            res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
            return res.json()
    
        def call(self, to, data):
            data = {"jsonrpc":"2.0","method":"eth_call","params":[{"to": to, "data": data}, "latest"],"id":1}
            res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
            return res.json()
    
        def send_raw_transaction(self, hex):
            """广播交易"""
            data = {"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":[hex],"id":1}
            res = requests.post(self.api, json=data, headers=headers,  proxies=self.proxies, timeout=self.timeout)
            return res.json()
    
        def get_balance(self, address):
            """获取余额"""
            data = {"jsonrpc":"2.0","method":"eth_getBalance","params":[address, 'latest'],"id":1}
            res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
            return res.json()#(int(res.json()['result'], 16)) / math.pow(10,18)
    
        def transfer(self, account, to, amount, gaslimit, **kw):
            amount = int(amount, 16) if isinstance(amount, str) else int(amount)
            gaslimit = int(gaslimit, 16) if not isinstance(gaslimit, int) else gaslimit
            gasprice = int(self.get_gas_price()['result'], 16)
            nonce = int(self.get_transaction_count_by_address(account.address)['result'], 16)
            tx = {'from': account.address, 'value': amount,'to': to, 'gas': gaslimit, 'gasPrice': gasprice, 'nonce': nonce, 'chainId': self.chainid}
            if kw:
                tx.update(**kw)
            signed = account.signTransaction(tx)
            return self.send_raw_transaction(signed.rawTransaction.hex())
    
    def claim(privkey):
        # 领取
        rpc = Rpc()
        # https://arbiscan.io/address/0x67a24CE4321aB3aF51c2D0a4801c3E111D88C9d9
        token = '0x67a24CE4321aB3aF51c2D0a4801c3E111D88C9d9' # 领取合约地址
        data = '0x4e71d92d'
        account = web3.Account.from_key(privkey)
        to = web3.Web3.toChecksumAddress(token)
        res = rpc.transfer(account, to, 0, gaslimit=455210, data=data)
        return res
    
    def collection(privkey, address):
        # 归集
        # https://arbiscan.io/token/0x912ce59144191c1204e64559fe8253a0e49e6548#balances
        rpc = Rpc()
        account = web3.Account.from_key(privkey)
        token = '0x912ce59144191c1204e64559fe8253a0e49e6548' # arb 代币地址
        # 1.查询地址余额
        call_data = '0x70a08231' + '000000000000000000000000' + account.address[2:]
        res = rpc.call(token, call_data)
        value = res['result']
        # 2.转账
        addr_1 = address.lower()[2:].rjust(64,'0')
        unit_2 = value[2:].rjust(64,'0')
        data = '0xa9059cbb' + addr_1 + unit_2
        to = web3.Web3.toChecksumAddress(token)
        res = rpc.transfer(account, to, 0, gaslimit=455210, data=data)
        return res
    
    if __name__ == '__main__':
        pk = 'xxxxxxx' # 你的私钥
        # 领取
        res = claim(pk)
        print(res)
        # 归集
        address = '' # 你的交易所钱包Arb地址
        res = collection(pk, address)
        print(res)
    

代码已上传

[

simple-airdrop-demo/arb-claim at main · junjie9021/simple-airdrop-demo
----------------------------------------------------------------------

Contribute to junjie9021/simple-airdrop-demo development by creating an account on GitHub.

https://github.com

![](https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png)

](https://github.com/junjie9021/simple-airdrop-demo/tree/main/arb-claim)

### 原理分析教程

*   [lifeform 的 free mint 代码交互排查思路](https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/etJQ20zi8b3pK1m0GfvnH8cnxoc9ErVhGKLk3YtKTIg)
    
*   [如何通过 rpc协议来交互 Base的存款](https://mirror.xyz/dashboard/edit/eLMoVNgxH-XZTCSQBdw41x_yDNlyxXy8DeWqGGbmz6o)
    

### 往期代码交互教程

*   [scroll alpha test bridge代码交互](https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/O04bGQYMc6H7fhYiCBdbpOAJl_ygG50ehW6LQRsRsvg)
    
*   [aave gho稳定币项目代码交互教程](https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/tdjYv4dEnsQry_U44kj0sbDa5htuRBYHpUf45w8v-qc)
    
*   [base 存款代码交互教程](https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/IeEw0Qp3MYbwFZx111fi1J25Dm8JLcm6avEHv_72R-0)
    
*   [sui mint nft 代码交互教程](https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/XHRTueAW7jk13TOHVdPchzkM38PnDxidsJqY2TCnqTQ)
    

我的 [推特](https://twitter.com/junjie9021) [Lens](https://lenster.xyz/u/0x049) [Link3](https://link3.to/junjie9021) [Github](https://github.com/junjie9021/simple-airdrop-demo)

---

*Originally published on [junjie9021](https://paragraph.com/@junjie9021-3/python-arb-demo)*
