geth web3提供的接口

{
  admin: {
    datadir: "/ethcluster/779977/data/01",
    nodeInfo: {
      enode: "enode://ca624860483a9f749676491bbf5b11cc7ded0a89f5c9f522767ebea0195c10dcee1b3ba8e7ca3de2857d4d2b29bf45380e274500c2bcb7b6cabafa52e201359d@[::]:30301",
      id: "ca624860483a9f749676491bbf5b11cc7ded0a89f5c9f522767ebea0195c10dcee1b3ba8e7ca3de2857d4d2b29bf45380e274500c2bcb7b6cabafa52e201359d",
      ip: "::",
      listenAddr: "[::]:30301",
      name: "Geth/01/v1.6.5-stable/linux-amd64/go1.8",
      ports: {
        discovery: 30301,
        listener: 30301
      },
      protocols: {
        eth: {...}
      }
    },
    peers: [{
        caps: [...],
        id: "7700ac997cb6f9ada772f09022c9ac4ec873b20645fa38f420a97fe2a0ed50b02a80d2901b10c6226033a31e82475eb57d5483a0fd6be6ea6261df148b117d93",
        name: "Geth/00/v1.6.5-stable/linux-amd64/go1.8",
        network: {...},
        protocols: {...}
    }, {
        caps: [...],
        id: "a8f9e6f118d20506fc5314a362d698d4fc3957c5f74ca325d89d6515c69cc69975891bf341757023949b8fe6168b492a8fcdc1a47fe1199b7d6f8399e26ecaea",
        name: "Geth/00/v1.6.5-stable/linux-amd64/go1.8",
        network: {...},
        protocols: {...}
    }],
    addPeer: function(),
    exportChain: function(),
    getDatadir: function(callback),
    getNodeInfo: function(callback),
    getPeers: function(callback),
    importChain: function(),
    removePeer: function(),
    sleep: function github.com/ethereum/go-ethereum/console.(*bridge).Sleep-fm(),
    sleepBlocks: function github.com/ethereum/go-ethereum/console.(*bridge).SleepBlocks-fm(),
    startRPC: function(),
    startWS: function(),
    stopRPC: function(),
    stopWS: function()
  },
  bzz: {
    hive: undefined,
    info: undefined,
    blockNetworkRead: function(),
    download: function(),
    get: function(),
    getHive: function(callback),
    getInfo: function(callback),
    modify: function(),
    put: function(),
    retrieve: function(),
    store: function(),
    swapEnabled: function(),
    syncEnabled: function(),
    upload: function()
  },
  currentProvider: {
    sign: undefined,
    newAccount: function(),
    send: function github.com/ethereum/go-ethereum/console.(*bridge).Send-fm(),
    sendAsync: function github.com/ethereum/go-ethereum/console.(*bridge).Send-fm(),
    unlockAccount: function()
  },
  db: {
    getHex: function(),
    getString: function(),
    putHex: function(),
    putString: function()
  },
  eth: {
    accounts: ["0x4c57e7e9c2f728046ddc6e96052056a241bdbd0a", "0xe82e2f0a5abd8774767b9751659976f9c4f59181"],
    blockNumber: 9389,
    coinbase: "0x4c57e7e9c2f728046ddc6e96052056a241bdbd0a",
    compile: {
      lll: function(),
      serpent: function(),
      solidity: function()
    },
    defaultAccount: undefined,
    defaultBlock: "latest",
    gasPrice: 18000000000,
    hashrate: 0,
    mining: false,
    pendingTransactions: [],
    protocolVersion: "0x3f",
    syncing: false,
    call: function(),
    contract: function(abi),
    estimateGas: function(),
    filter: function(fil, callback),
    getAccounts: function(callback),
    getBalance: function(),
    getBlock: function(),
    getBlockNumber: function(callback),
    getBlockTransactionCount: function(),
    getBlockUncleCount: function(),
    getCode: function(),
    getCoinbase: function(callback),
    getCompilers: function(),
    getGasPrice: function(callback),
    getHashrate: function(callback),
    getMining: function(callback),
    getPendingTransactions: function(callback),
    getProtocolVersion: function(callback),
    getRawTransaction: function(),
    getRawTransactionFromBlock: function(),
    getStorageAt: function(),
    getSyncing: function(callback),
    getTransaction: function(),
    getTransactionCount: function(),
    getTransactionFromBlock: function(),
    getTransactionReceipt: function(),
    getUncle: function(),
    getWork: function(),
    iban: function(iban),
    icapNamereg: function(),
    isSyncing: function(callback),
    namereg: function(),
    resend: function(),
    sendIBANTransaction: function(),
    sendRawTransaction: function(),
    sendTransaction: function(),
    sign: function(),
    signTransaction: function(),
    submitTransaction: function(),
    submitWork: function()
  },
  isIBAN: undefined,
  net: {
    listening: true,
    peerCount: 2,
    version: "779977",
    getListening: function(callback),
    getPeerCount: function(callback),
    getVersion: function(callback)
  },
  personal: {
    listAccounts: undefined,
    getListAccounts: function(callback),
    lockAccount: function(),
    newAccount: function github.com/ethereum/go-ethereum/console.(*bridge).NewAccount-fm(),
    sendTransaction: function(),
    sign: function github.com/ethereum/go-ethereum/console.(*bridge).Sign-fm(),
    unlockAccount: function github.com/ethereum/go-ethereum/console.(*bridge).UnlockAccount-fm()
  },
  providers: {
    HttpProvider: function(host, timeout),
    IpcProvider: function(path, net)
  },
  rpc: {
    modules: {
      admin: "1.0",
      eth: "1.0",
      net: "1.0",
      rpc: "1.0",
      web3: "1.0"
    },
    getModules: function(callback)
  },
  settings: {
    defaultAccount: undefined,
    defaultBlock: "latest"
  },
  shh: {
    addToGroup: function(),
    filter: function(fil, callback),
    hasIdentity: function(),
    newGroup: function(),
    newIdentity: function(),
    post: function()
  },
  version: {
    api: "0.18.1",
    ethereum: "0x3f",
    network: "779977",
    node: "Geth/01/v1.6.5-stable/linux-amd64/go1.8",
    whisper: undefined,
    getEthereum: function(callback),
    getNetwork: function(callback),
    getNode: function(callback),
    getWhisper: function(callback)
  },
  BigNumber: function BigNumber( n, b ),
  createBatch: function(),
  fromAscii: function(str),
  fromDecimal: function(value),
  fromICAP: function(icap),
  fromUtf8: function(str),
  fromWei: function(number, unit),
  isAddress: function(address),
  isChecksumAddress: function(address),
  isConnected: function(),
  reset: function(keepIsSyncing),
  setProvider: function(provider),
  sha3: function(string, options),
  toAscii: function(hex),
  toBigNumber: function(number),
  toChecksumAddress: function(address),
  toDecimal: function(value),
  toHex: function(val),
  toUtf8: function(hex),
  toWei: function(number, unit)
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
首先,你需要安装web3 python库。可以使用以下命令进行安装: ``` pip install web3 ``` 接下来,你需要连接到以太坊网络。这可以通过以下方式完成: ```python from web3 import Web3 # 连接到以太坊网络 w3 = Web3(Web3.HTTPProvider("https://mainnet.infura.io/v3/<your-infura-project-id>")) ``` 在连接到以太坊网络之后,你可以使用以下代码查询报价: ```python # 导入需要的模块 from web3 import Web3 from web3.middleware import geth_poa_middleware # 连接到以太坊网络 w3 = Web3(Web3.HTTPProvider("https://mainnet.infura.io/v3/<your-infura-project-id>")) # 添加POA中间件以支持以太坊网络 w3.middleware_onion.inject(geth_poa_middleware, layer=0) # 定义合约地址和ABI uniswap_address = "0x7a250d5630b4cf539739df2c5dacb4c659f2488d" uniswap_abi = [{"constant": True, "inputs": [{"internalType": "address", "name": "", "type": "address"}, {"internalType": "address", "name": "", "type": "address"}], "name": "getAmountsOut", "outputs": [{"internalType": "uint256[]", "name": "", "type": "uint256[]"}], "payable": False, "stateMutability": "view", "type": "function"}] # 创建合约实例 uniswap = w3.eth.contract(address=uniswap_address, abi=uniswap_abi) # 定义输入参数 token_in = w3.toChecksumAddress("0x6b175474e89094c44da98b954eedeac495271d0f") # DAI地址 token_out = w3.toChecksumAddress("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2") # WETH地址 amount_in = w3.toWei(100, "ether") # 输入数量 # 调用getAmountsOut函数查询报价 quote = uniswap.functions.getAmountsOut(amount_in, [token_in, token_out]).call() # 显示报价 print("100 DAI 可以换取的 WETH 数量为:", w3.fromWei(quote[1], "ether")) ``` 这个代码片段使用了Uniswap合约来查询报价。你需要提供正确的合约地址和ABI,并使用正确的输入参数来获取所需的报价。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值