Я установил web3, чтобы связать Solidity с React-native.Как и в приведенном ниже коде, я развернул его из Remix и ввел адрес и ABI.
import Web3 from "web3";
const web3 = new Web3(
new Web3.providers.HttpProvider("https://127.0.0.1:8545")
);
const address = "0x6cc33e32853a7fb0ac9ac2fb0d54cb56e4fb0f30";
const abi = [
{
constant: false,
inputs: [
{
name: "_MASTER",
type: "address"
},
{
name: "_sitter",
type: "address"
},
{
name: "_sitterprice",
type: "uint256"
}
],
name: "CompleteSharePet",
outputs: [],
payable: true,
stateMutability: "payable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_OWNER",
type: "address"
},
{
name: "_ownersharetext",
type: "string"
},
{
name: "_ownerprice",
type: "uint256"
}
],
name: "OwnerShareText",
outputs: [
{
name: "",
type: "string"
}
],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_ownerseller",
type: "address"
},
{
name: "_petsitter",
type: "address"
},
{
name: "_MASTER",
type: "address"
},
{
name: "_ownerprice",
type: "uint256"
}
],
name: "PetChange",
outputs: [],
payable: true,
stateMutability: "payable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_PETSITTER",
type: "address"
},
{
name: "_master",
type: "address"
},
{
name: "_ownerprice",
type: "uint256"
}
],
name: "PetChangeTransaction",
outputs: [],
payable: true,
stateMutability: "payable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_petsittertext",
type: "string"
},
{
name: "_sitterprice",
type: "uint256"
}
],
name: "PetSitterShareText",
outputs: [
{
name: "",
type: "string"
}
],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_sitter",
type: "address"
}
],
name: "testsitter",
outputs: [],
payable: true,
stateMutability: "payable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_master",
type: "address"
},
{
name: "_OWNER",
type: "address"
},
{
name: "_sitterprice",
type: "uint256"
}
],
name: "TransactionSharePet",
outputs: [],
payable: true,
stateMutability: "payable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "hash",
type: "string"
},
{
name: "ipfs",
type: "string"
}
],
name: "uploadImage",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: true,
inputs: [],
name: "AllOwnerCount",
outputs: [
{
name: "",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [],
name: "AllPetSitter",
outputs: [
{
name: "",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [],
name: "getOwnerAddresses",
outputs: [
{
name: "",
type: "address[]"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "_owner",
type: "address"
}
],
name: "getOwnerInfo",
outputs: [
{
name: "",
type: "string"
},
{
name: "",
type: "string"
},
{
name: "",
type: "string"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [],
name: "getPetSitterAddresses",
outputs: [
{
name: "",
type: "address[]"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "_petsitter",
type: "address"
}
],
name: "getPetSitterInfo",
outputs: [
{
name: "",
type: "string"
},
{
name: "",
type: "string"
},
{
name: "",
type: "string"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "",
type: "uint256"
}
],
name: "OwnerAddresses",
outputs: [
{
name: "",
type: "address"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "",
type: "uint256"
}
],
name: "PetSitterAddresses",
outputs: [
{
name: "",
type: "address"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "_OWNER",
type: "address"
}
],
name: "test",
outputs: [
{
name: "",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "_MASTER",
type: "address"
}
],
name: "test2",
outputs: [
{
name: "",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
}
];
export class WalletSetting extends Component {
test() {
web3.eth.getAccounts().then(console.log);
}
render() {
return this.test;
}
}
export default (myContract = new web3.eth.Contract(abi, address));
Параметр был безошибочным, но произошла ошибка при импорте с использованием mycontact
import WalletSetting from "../web3";
.
.
.
</TouchableOpacity>
<WalletSetting />
</LinearGradient>
Изображение ошибки
Я удалил все node_modules и весь кэш, как показано на рисунке.Однако произошла та же ошибка, и, хотя мы тщательно искали с помощью поиска в Goolgle, мы еще не решили ее.
Я жду хорошего ответа.Пожалуйста, помогите мне с решением.
Я загрузил версию web3 как «^ 1.0.0-beta.34», чтобы устранить существующую ошибку, но произошла другая ошибка.
Ошибкаis
Невозможно разрешить модуль crypto
из /Users/lucky/pettest/node_modules/web3-eth-accounts/src/index.js
: Модуль crypto
не существует на карте модулей Haste
Поэтому я отправился в Google для справки https://gist.github.com/dougbacelar/29e60920d8fa1982535247563eb63766И установите "node-libs-browser": "^ 2.2.0", "babelpresetes2015": "^ 6.24.1", и создайте файл с именем rn-cli.config.js, global.js и импортируйте файл globaljs вВаш файл web3.js, но ошибка была той же.
Как я могу это исправить?
https://gist.github.com/dougbacelar/29e60920d8fa1982535247563eb63766
Это решение не поможет решить мою проблему.