options - 合约配置对象

优质
小牛编辑
130浏览
2023-12-01

合约实例的可选配置对象。当发送交易时,其from、gas和gasPrice被用作回调值。

调用:

myContract.options

options属性对象具有以下字段:

  • address - String: 合约的部署地址
  • jsonInterface - Array: 合约的json接口
  • data - String: 合约的字节码,合约部署时会用到
  • from - String: 合约发送方账户地址
  • gasPrice - String: 用于交易的gas价格,单位:wei
  • gas - Number: 交易的gas用量上限,即gas limit

示例代码:

myContract.options;
> {
    address: '0x1234567890123456789012345678901234567891',
    jsonInterface: [...],
    from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe',
    gasPrice: '10000000000000',
    gas: 1000000
}

myContract.options.from = '0x1234567890123456789012345678901234567891'; // default from address
myContract.options.gasPrice = '20000000000000'; // default gas price in wei
myContract.options.gas = 5000000; // provide as fallback always 5M gas