如何从地址调用不同的合约?

2024-01-28

在 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 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/ https://gateway.ipfs.io/ipfs/QmPvcjeEE5PJvaJNN2axgKVWGbWVEQCe9q4e95t9NCeGFt/


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

        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,
        ))

from https://github.com/near/core-contracts/blob/cd221798a77d646d5f1200910d45326d11951732/lockup/src/owner.rs#L29-L40 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;
}

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何从地址调用不同的合约? 的相关文章

随机推荐