BlockchainTransaction (for Ethereum)
BlockchainTransaction[assoc]
表示一个根据关联 assoc 中的元素构建的以太坊区块链交易.
更多信息
- 给出以太坊区块链交易的符号表示;它不提交交易,并且交易是未签名的.
- BlockchainTransaction[…][prop] 给出交易的属性 prop 的值.
- 必须给出以下元素:
-
"TransactionCount" 与账户相关的交易的次数 "GasPrice" 每个 gas 的价钱,单位为 wei - 另外还可以给出"GasLimit" 元素. 默认情况下,在内部对其进行计算:
-
"GasLimit" 执行的 gas 的最大量 - 当进行转账时,必须给出以下元素:
-
"Address" 转帐的地址 "Amount" 转移的 wei 的数量 - 部署合约时,必须给出以下元素:
-
"Contract" 要在交易中部署的合约 - 在使用纯 Solidity 代码时,合约必须是包含代码的字符串,如 "Contract""code".
- 当使用有多个合约的纯 Solidity 代码时,必须用关联 <|"SourceCode""code","Main""name"|> 指定 "Contract",其中 "Main" 是要部署的合约的名称.
- 在提供含有 Solidity 代码的文件时,合约必须是一个 File,如 "Contract"->File[…].
- 在提供含有 Solidity 代码且该代码含有多个合约的文件时,必须用关联 <|"Source"File[…],"Main""name"|> 指定 "Contract",其中 "Main" 是要部署的合约的名称.
- 当提供多个含有 Solidity 代码的文件时,必须用关联 <|"Source"{file1,file2,…},"Main""name"|> 指定 "Contract",其中 {file1,file2,…} 是 File 表达式列表,其中 file1 将被编译,"Main" 是要部署的合约的名称.
- 在使用编译过的 Solidity 代码时,必须用关联 <|"ByteCode""hexstring","ABI""spec"|> 指定 "Contract",其中 "ABI" 为 Application Binary Interface.
- 另外,在提供 "Contract" 的关联时,可给出额外的 "Parameters" 属性,以定义要部署的合约的初始化参数.
- 在以太坊交易中部署自动执行的 Wolfram 语言表达式时,可以给出以下元素:
-
"WolframExpression" harvest 时要计算的表达式 "WolframExpressionReference" 对要获取和计算的表达式的指代 - 包含 Wolfram 语言表达式的以太坊交易只能部署到以太坊 testnet.
- 在调用合约时,必须给出以下元素:
-
"Address" 合约的地址 "FunctionCall" 合约中要进行的函数调用 - "FunctionCall" 元素可以是 Association 或 Typed 表达式.
- 如果 "FunctionCall" 是一个 Typed 表达式,它必须定义函数名称.
- 如果 "FunctionCall" 是一个 Association 表达式,则必须给出以下属性:
-
"Function" 定义要调用的函数的 Typed 表达式 - 也可将以下其他属性赋给 "FunctionCall" 关联:
-
"Inputs" 要调用的函数的输入参数 "Sender" 调用合约的发送者的地址 - 也可从 BlockchainTransaction 对象获取以下其他属性:
-
"Signed" 一个交易是否已有数字签名 "MessageHash" 未签名交易的哈希 "RawTransaction" 序列化交易 "TransactionID" 交易的 ID - BlockchainTransaction 可表示 Ethereum mainnet(默认)和 testnet (Sepolia) 交易. 如果想指定该网络,请在相应的关联中指定 "BlockchainBase" 的值或使用 BlockchainBase 选项.
范例
打开所有单元 关闭所有单元基本范例 (2)
BlockchainTransaction[<|"TransactionCount" -> 58,
"GasPrice" -> Quantity[1, "GWei"], "Address" -> "3535353535353535353535353535353535353535",
"BlockchainBase" -> {"Ethereum", "Testnet"}|>]BlockchainTransaction[<|"TransactionCount" -> 58,
"GasPrice" -> Quantity[1, "GWei"], "GasLimit" -> 21000,
"Address" -> "3535353535353535353535353535353535353535",
"Amount" -> Quantity[0.0025, "Ethers"],
"BlockchainBase" -> {"Ethereum", "Testnet"}|>]范围 (7)
纯文本 Solidity 合约 (2)
solidityCode = "pragma solidity ^0.4.23;
contract Test{
function sum(uint256 a, uint256 b) public pure returns (uint256)
{
return a+b;
}
}
";BlockchainTransaction[<|"TransactionCount" -> 58,
"GasPrice" -> Quantity[1, "GWei"],
"Contract" -> solidityCode,
"BlockchainBase" -> {"Ethereum", "Testnet"}|>]solidityCode = "pragma solidity ^0.4.23;
contract Test2{
function sum(uint256 a, uint256 b) public pure returns (uint256){
return a+b;
}
}
contract Test is Test2{
function main(uint256 a,uint256 b) public pure returns (uint256){
return sum(a,b);
}
}";BlockchainTransaction[<|"TransactionCount" -> 58,
"GasPrice" -> Quantity[1, "GWei"],
"Contract" -> solidityCode,
"BlockchainBase" -> {"Ethereum", "Testnet"}|>]Solidity 合约文件 (1)
Import[File["ExampleData/sample.sol"]]BlockchainTransaction[<|"TransactionCount" -> 59,
"GasPrice" -> Quantity[1, "GWei"],
"Contract" -> <|"SourceCode" -> solidityCode, "Main" -> "Test"|>,
"BlockchainBase" -> {"Ethereum", "Testnet"}|>]Import[File["ExampleData/sample2.sol"]]BlockchainTransaction[<|"BlockchainBase" -> {"Ethereum", "Testnet"}, "TransactionCount" -> 61, "Contract" -> <|"Source" -> File["ExampleData/sample2.sol"], "Main" -> "Test"|>, "GasPrice" -> Quantity[1, "Gwei"]|>]Import[File["ExampleData/sample3.sol"]]Import[File["ExampleData/sample4.sol"]]BlockchainTransaction[<|"BlockchainBase" -> {"Ethereum", "Testnet"}, "TransactionCount" -> 61, "Contract" -> <|"Source" -> {File["ExampleData/sample4.sol"], File["ExampleData/sample3.sol"]}, "Main" -> "Test4"|>, "GasPrice" -> Quantity[1, "Gwei"]|>]已编译 Solidity 合约 (1)
bytecode = "608060405234801561001057600080fd5b506040516104503803806104508339810180604052810190808051820192919060200180518201929190602001805190602001909291905050508260009080519060200190610060929190610087565b508160019080519060200190610077929190610087565b508060028190555050505061012c565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100c857805160ff19168380011785556100f6565b828001600101855582156100f6579182015b828111156100f55782518255916020019190600101906100da565b5b5090506101039190610107565b5090565b61012991905b8082111561012557600081600090555060010161010d565b5090565b90565b6103158061013b6000396000f300608060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063047fc9aa1461005c57806306fdde031461008757806354fd4d5014610117575b600080fd5b34801561006857600080fd5b506100716101a7565b6040518082815260200191505060405180910390f35b34801561009357600080fd5b5061009c6101ad565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100dc5780820151818401526020810190506100c1565b50505050905090810190601f1680156101095780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561012357600080fd5b5061012c61024b565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561016c578082015181840152602081019050610151565b50505050905090810190601f1680156101995780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60025481565b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102435780601f1061021857610100808354040283529160200191610243565b820191906000526020600020905b81548152906001019060200180831161022657829003601f168201915b505050505081565b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102e15780601f106102b6576101008083540402835291602001916102e1565b820191906000526020600020905b8154815290600101906020018083116102c457829003601f168201915b5050505050815600a165627a7a72305820116f53a6040b598029b8580eb96cf331f11fc8a7ba722618dfd5dd8df8601f9e0029";abi = "[{\"constant\":true,\"inputs\":[],\"name\":\"supply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_name\",\"type\":\"string\"},{\"name\":\"_version\",\"type\":\"string\"},{\"name\":\"_supply\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]";BlockchainTransaction[<|"BlockchainBase" -> {"Ethereum", "Testnet"}, "TransactionCount" -> 62, "Contract" -> <|"ABI" -> abi, "ByteCode" -> bytecode, "Parameters" -> {"hello", "world", 10005}|>, "GasPrice" -> Quantity[1, "Gwei"]|>]Wolfram 语言表达式 (2)
用 Wolfram 语言表达式构建合约. 此表达式将由 Wolfram 服务器计算:
BlockchainTransaction[<|"BlockchainBase" -> {"Ethereum", "Testnet"}, "TransactionCount" -> 63, "WolframExpression" -> Delayed[WeatherData[Entity["City", {"Lima", "Lima", "Peru"}], "Temperature"]], "GasPrice" -> Quantity[1, "Gwei"]|>]用外部存储对象指代的 Wolfram 语言表达式构建合约. Wolfram 服务器将对指代进行计算:
ipfsobj = ExternalStorageUpload["ExampleData/simple.m"]BlockchainTransaction[<|"BlockchainBase" -> {"Ethereum", "Testnet"}, "TransactionCount" -> 64, "WolframExpressionReference" -> ipfsobj, "GasPrice" -> Quantity[1, "Gwei"]|>]%["WolframExpressionReference"]普通的合约调用 (1)
contractAddress = "D3201000dDa9de4f04F53B50DcfEc9Af3FBA25a7";BlockchainTransaction[<|"BlockchainBase" -> {"Ethereum", "Testnet"}, "TransactionCount" -> 64, "WolframExpressionReference" -> ipfsobj, "GasPrice" -> Quantity[1, "Gwei"]|>]选项 (2)
BlockchainBase (2)
Mainnet (1)
应用 (1)
创建一个以太坊 BlockchainTransaction:
ethTX = BlockchainTransaction[<|"BlockchainBase" -> {"Ethereum", "Testnet"},
"TransactionCount" -> 11,
"GasPrice" -> Quantity[150, "GWei"],
"Address" -> "61cccDcDb7617d01239D0Cfc7D1627e39EA2a2c3",
"Amount" -> Quantity[0.50, "Ethers"]|>]ethTXSigned = BlockchainTransactionSign[ethTX, PrivateKey[Association["Type" -> "EllipticCurve", "CurveName" -> "secp256k1",
"PublicCurvePoint" ->
{16676173248318435135530093705658075451448270649776782441185582813615674064589,
86146693258001150152237806044792681696883435827253397319 ... 84,
"Compressed" -> False, "PublicByteArray" ->
ByteArray[
"BCTeYSvTb1h4i8B8nUtJrM//zRHHu7GdlW16oP8LZ37NvnVM7PCJ8Qms/BwonG76LAj2PCP+VGbfyw1cFM21dNI="],
"PrivateByteArray" -> ByteArray["q/aGR9Z8/pp7h2fSVcu50AHSi8r4pHPKW97/exaY34w="]]]]ethTXSubmit = BlockchainTransactionSubmit[ethTXSigned]txdata = BlockchainTransactionData[ethTXSubmit["TransactionID"], BlockchainBase -> {"Ethereum", "Testnet"}]相关指南
-
▪
- 使用以太坊区块链
历史
2019年引入 (12.0)
文本
Wolfram Research (2019),BlockchainTransaction,Wolfram 语言函数,https://reference.wolfram.com/language/ref/blockchain/BlockchainTransaction-Ethereum.html.
CMS
Wolfram 语言. 2019. "BlockchainTransaction." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/blockchain/BlockchainTransaction-Ethereum.html.
APA
Wolfram 语言. (2019). BlockchainTransaction. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/blockchain/BlockchainTransaction-Ethereum.html 年
BibTeX
@misc{reference.wolfram_2026_blockchaintransaction, author="Wolfram Research", title="{BlockchainTransaction}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/blockchain/BlockchainTransaction-Ethereum.html}", note=[Accessed: 18-August-2026]}
BibLaTeX
@online{reference.wolfram_2026_blockchaintransaction, organization={Wolfram Research}, title={BlockchainTransaction}, year={2019}, url={https://reference.wolfram.com/language/ref/blockchain/BlockchainTransaction-Ethereum.html}, note=[Accessed: 18-August-2026]}