【问题标题】:How to call different contract from its address?如何从其地址调用不同的合约?
【发布时间】:2020-12-31 21:16:13
【问题描述】:

在solidity(以太坊)中,需要合约地址来调用该合约。

contract KittyInterface {
  function getKitty(uint256 _id) external view returns (
    bool isGestating,
    bool isReady,
    uint256 cooldownIndex,
    uint256 nextActionAt,
    uint256 siringWithId,
    uint256 birthTime,
    uint256 matronId,
    uint256 sireId,
    uint256 generation,
    uint256 genes
  );
}

contract ZombieFeeding is ZombieFactory {

  address ckAddress = 0x06012c8cf97BEaD5deAe237070F9587f8E7A266d; 
  KittyInterface kittyContract = KittyInterface(ckAddress);

我可以在近距离协议中这样做吗? 附近的示例有些不同,需要提供 wasm 文件。 https://github.com/near-examples/rust-high-level-cross-contract

pub fn deploy_status_message(&self, account_id: String, amount: u64) {
        Promise::new(account_id)
            .create_account()
            .transfer(amount as u128)
            .add_full_access_key(env::signer_account_pk())
            .deploy_contract(
                include_bytes!("../status-message-contract/status_message.wasm").to_vec(),
            );
    }

另外,我在使用高级交叉合约代码时遇到了错误。 https://gateway.ipfs.io/ipfs/QmPvcjeEE5PJvaJNN2axgKVWGbWVEQCe9q4e95t9NCeGFt/

【问题讨论】:

    标签: nearprotocol


    【解决方案1】:

    请看一下锁定合约示例。它使用以下内容:

            ext_whitelist::is_whitelisted(
                staking_pool_account_id.clone(),
                &self.staking_pool_whitelist_account_id,
                NO_DEPOSIT,
                gas::whitelist::IS_WHITELISTED,
            )
            .then(ext_self_owner::on_whitelist_is_whitelisted(
                staking_pool_account_id,
                &env::current_account_id(),
                NO_DEPOSIT,
                gas::owner_callbacks::ON_WHITELIST_IS_WHITELISTED,
            ))
    

    来自https://github.com/near/core-contracts/blob/cd221798a77d646d5f1200910d45326d11951732/lockup/src/owner.rs#L29-L40

    第一个调用接口是(<arg_0>, <arg_1>, ..., <arg_n>, <ACCOUNT_ID>, <ATTACHED_DEPOSIT>, <ATTACHED_GAS>)

    • <arg_0>, <arg_1>, ..., <arg_n> - 来自下面定义的接口的参数
    • <ACCOUNT_ID> - 部署合约调用的账户
    • <ATTACHED_DEPOSIT> - yocto-NEAR 中附加到呼叫的金额
    • <ATTACHED_GAS> - 传递给调用的 Gas 数量

    它后来使用.then 将回调附加到第一个承诺。回调只是另一个异步函数调用。

    高级接口ext_whitelist是这样定义的:

    #[ext_contract(ext_whitelist)]
    pub trait ExtStakingPoolWhitelist {
        fn is_whitelisted(&self, staking_pool_account_id: AccountId) -> bool;
    }
    

    来自https://github.com/near/core-contracts/blob/cd221798a77d646d5f1200910d45326d11951732/lockup/src/lib.rs#L64-L67

    【讨论】:

      猜你喜欢
      • 2018-02-04
      • 2018-07-12
      • 2022-11-13
      • 1970-01-01
      • 2021-09-07
      • 1970-01-01
      • 1970-01-01
      • 2018-08-01
      • 1970-01-01
      相关资源
      最近更新 更多